2014-03-14 2 views
1

기본적으로 비디오는 동일한 방법으로 작동하도록합니다. background-size:cover - 사용 가능한 모든 공간을 감추고 있습니다 (예 : http://www.aaronvanderzwan.com/maximage/examples/html5video.html). 비례 적으로 크기를 조정하고 중심에 맞춰야하지만, 여전히 사용 가능한 공간을 모두 차지하지는 않습니다.사용 가능한 모든 공간을 포함하는 전체 화면 배경 비디오

자바 스크립트 :

$(document).ready(function(e){ 

    var $item = $(".video"); 
    var proportions = $item.width()/$item.height() 


    // shim layer with setTimeout fallback 
    window.requestAnimFrame = (function(){ 
    return window.requestAnimationFrame  || 
      window.webkitRequestAnimationFrame || 
      window.mozRequestAnimationFrame || 
      function(callback){ 
       window.setTimeout(callback, 1000/60); 
      }; 
    })(); 



    // usage: 
    // instead of setInterval(render, 16) .... 
    (function animloop(){ 
    requestAnimFrame(animloop); 
    resize(); 
    })(); 


    function resize(){ 

    // center the item 
    $item.css({"top": "50%", "margin-top":-parseInt($item.height()/2)}) 
    $item.css({"left": "50%", "margin-left":-parseInt($item.width()/2)}) 


    // scale it 
    if($(window).width()/$(window).height() < proportions){ 
     scaleProportionalByHeight($(window).height()) 
    }else{ 
     scaleProportionalByWidth($(window).width()) 
    } 
    } 



    function scaleProportionalByWidth (newWidth) { 
    $item.width(newWidth); 
    $item.height(newWidth/proportions); 
    } 

    function scaleProportionalByHeight (newHeight ) { 
    $item.height(newHeight); 
    $item.width(newHeight * proportions); 
    } 

}) 

HTML :

<video class="video" loop autoplay muted autobuffer="autobuffer"> 
    <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4"> 
</video> 
+0

그것은 아직 좋은 지원이없는 불쌍'객체 fit' 재산이다 (여기 참조 : http://caniuse.com/object-fit) 그것은 당신이 필요로하는 것을 exacly하지 않습니다 : http://jsfiddle.net/chadocat/V6rPP/12/ (크롬 32+ 그 효과를 확인하십시오. –

답변

0

당신은 그냥 사용할 수 없습니다 CSS? 이 같은

:

HTML

<video loop autoplay muted autobuffer="autobuffer" id="myVideo"> 
    <source src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" type="video/mp4"> 
</video> 

CSS

video#myVideo{ 
    position: fixed; right: 0; bottom: 0; 
    width: auto; height: auto; z-index: -100; 
    min-width: 100%; min-height: 100%; 
    background-size: cover; 
} 
+1

흠 .. 몇 가지 테스트를 한 후에 예상대로 작동하지 않습니다. 오른쪽 때문에 : 0; 하단 : 0. 비디오는 비례 적으로 화면을 채우도록 크기가 조절되지만 오른쪽으로는 0, 아래쪽으로는 0이므로 올바르게 중앙에 배치되지 않습니다. – fjckls

관련 문제