所以我有一个视频,我用 jQuery 的 .load() 加载到页面中。这是您可以在“视频”部分看到问题的网站:http: //guillaumep.com/。
这是我必须使用的视频标签:
<video><source src="URLTOVIDEO.mp4" type="video/mp4" />
这是在加载到 my 后立即生成视频 HTML 的代码#contentFrame
:
$('video').wrap('<div class="videowrapper">')
.attr({ 'style': 'width: 100%; height: 100%;' })
.mediaelementplayer({ success: function (player) {
correctVideoSize($(player).parent(4).eq(0)); }
});
然后我有代码可以根据窗口的形状实际调整视频播放器的大小,以便视频始终以最大尺寸显示,而不会溢出窗口:
function correctVideoSize(videoContainer) {
var videoContainerHeight = $(window).height() - 100;
var videoContainerWidth = $(window).width() * 0.92;
var videoContainerRatio = videoContainerWidth / videoContainerHeight;
var videoRatio = videoContainer.width() / videoContainer.height();
console.log('videoRatio : ' + videoRatio);
console.log('videoContainerRatio : ' + videoContainerRatio);
if (!isNaN(videoRatio) && videoContainerRatio < videoRatio)
{
videoContainer.height(videoContainerWidth / videoRatio).width(videoContainerWidth);
}
else if (!isNaN(videoRatio))
{
videoContainer.height(videoContainerHeight).width(videoContainerHeight * videoRatio);
}
return videoContainer;
}
以这种方式调整图像大小绝对有效,如您所见: http: //guillaumep.com,但对于视频,我不明白我应该如何、何时、何地以及在何处调整大小。您可以在这里看到问题:http: //guillaumep.com/2012/10/22/test-video/。
我尝试了很多不同的东西,并让视频在 $(window).resize() 事件上正确调整大小,但我猜只是因为 MediaElementJs 已经挂钩到这个事件并做了一些魔术。
我真的迷路了,感谢您的帮助!