无信箱的全背景 HTML5 视频
这里有很多关于如何制作背景 HTML5 视频的问题,但我对此没有任何问题,它工作得很好(除了一个小问题,它只会播放音频而不是视频,直到我在页面上选择某些内容或调整它的大小) ,请参阅此处了解该问题:
我想要做的是使视频适合背景,这样它就不会出现任何信箱(当长宽比不匹配时,上方/下方或两侧的线条)。当高度小于比例时适合宽度,当宽度小于比例时适合高度
这会切断一些视频,但没关系,我只是想摆脱信箱有什么办法。只用 CSS 来做到这一点,如果 我需要使用什么 javascript/jQuery/什么?
到目前为止
#mashvid {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: auto;
min-width: 100%;
z-index: -5;
}
<video preload id="mashvid" poster="images/mashvid_poster.png">
<source src="http://www.mashwork.com/testsite/video/mashwork1080.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
<source src="http://www.mashwork.com/testsite/video/mashwork1080.ogv" type='video/ogg; codecs="theora, vorbis"'>
<source src="http://www.mashwork.com/testsite/video/mashwork1080.webm" type='video/webm; codecs="vp8, vorbis"'>
Your browser does not support the video tag.
</video>
There are many questions on here regarding how to do background HTML5 video, but I have no issue with that, it works fine (except for a small issue where it will only play audio and not video until I select something on the page or resize it, see here for that issue: Chrome Only Plays Audio Until Resize
What I want to do is make the video fit the background so that it never has any letterboxing (the lines above/below or on the sides when the aspect ration doesn't match). That means fit width when the height is less than the ratio, and fit height when the width is less than the ratio.
This will cut off some of the video, but that's fine, I just want to get rid of the letterboxing. Is there any way to do this with just CSS, and if not what javascript/jQuery/whatever do I need to use?
My code so far:
#mashvid {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: auto;
min-width: 100%;
z-index: -5;
}
<video preload id="mashvid" poster="images/mashvid_poster.png">
<source src="http://www.mashwork.com/testsite/video/mashwork1080.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>
<source src="http://www.mashwork.com/testsite/video/mashwork1080.ogv" type='video/ogg; codecs="theora, vorbis"'>
<source src="http://www.mashwork.com/testsite/video/mashwork1080.webm" type='video/webm; codecs="vp8, vorbis"'>
Your browser does not support the video tag.
</video>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我是这样解决的,虽然我不确定它有多坚固
I solved it like this, although I'm not sure how solid it is
我尝试过两 (2) 个不同的 jQuery 插件,它们在这个问题上做得相当好。
http://github.com/georgepaterson/jquery-videobackground
一个不错的插件,具有回调和导航/控制功能和样式,不适用于移动“so-far-ee”,但在 Windows 和 osx lion 上非常好。
和
http://syddev.com/jquery.videoBG/
一个更简单的插件,更容易定制,但也不太健壮,与移动 safari 存在同样的问题,但在其他方面非常有能力。
我发现的问题是,缩放附加到正文的 bg 视频或 img bg 在 diff OS
bot safari 和 ie 上的 smae 浏览器中表现不同,而 ie 拒绝在 Windows 平台上根据我的喜好缩放宽度,但在 osx 上表现如预期,您的里程可能会有所不同
=-)
I have tried two (2) different jQuery plugins that do a fairly good job with this issue.
http://github.com/georgepaterson/jquery-videobackground
a nice plugin, with callbacks and nav/control functionas and styles, does not work on mobile "so-far-ee" but very nice on windows and osx lion.
and
http://syddev.com/jquery.videoBG/
a simpler plugin easier to customize, but also less robust, same issues with mobile safari but v ery capable otherwise.
the issue i have found is that scaling bg video or img bg attched to body will behave differently in smae browser on diff OS
bot safari and ie refuse to scale width to my liking on windows platforms but behave as expected on osx, your mileage may vary
=-)