对于 HTML5video
元素,缩放其中一个维度会导致另一个维度自动缩放以保持纵横比。因此,如果您将元素的height
of设置为of ,并将其居中在一个包含set to的包含中,您应该会得到您正在寻找的效果。video
height
window
div
overflow
hidden
HTML:
<div id="container">
<video id="player" autoplay loop>
<source src="http://inoq.com/lxgo2/videos/transtejo.mp4" type="video/mp4" />
<source src="http://inoq.com/lxgo2/videos/transtejo.webm" type="video/webm" />
<source src="http://inoq.com/lxgo2/videos/transtejo.ogv" type="video/ogg" />
Your browser does not support the video tag.
</video>
</div>
JavaScript:
// Using jQuery for ease
var $player = $('#player');
var $window = $(window);
// if you only set one of width and height, the other dimension is automatically
// adjusted appropriately so that the video retains its aspect ratio.
// http://dev.opera.com/articles/view/everything-you-need-to-know-about-html5-video-and-audio/
$player[0].height = $window.height();
// centre the video
$player.css('left', (($window.width() - $player.width()) / 2) + "px");
CSS:
#container {
position: absolute;
width: 100%;
height: 100%;
overflow: hidden;
}
#player {
position: absolute;
}