Internet Explorer中的全角背景视频

时间:2015-12-17 06:32:23

标签: internet-explorer html5-video webm

我正在设计一个在100%宽度容器中使用自托管背景视频的网站。在Chrome和Firefox中完美运行但在IE中失败(在IE 11中测试)。

视频应该以宽度方式拉伸以填充容器 - 保持视频比例,但是,IE只是将视频放置在容器中,其大小必须垂直填充容器。

Screenshot of video stretching to fill container width in Chrome Screenshot of video failing to fill container in IE

Link to Page with Error

4 个答案:

答案 0 :(得分:7)

/*you can use this css.*/

.fullwidth-video {
position: absolute;
top: 0;
left: 0;
z-index: 1;
min-height: 100%;
min-width: 100%;
-webkit-transform-style: preserve-3d;
}
.fullwidth-video video {
position: absolute;
top: 0;
left: 0;
z-index: 1;
min-height: 100%;
min-width: 100%;
height: auto;
width: 100%;
object-fit: cover;
}
这里的HTML代码......

     <div class="fullwidth-video">
     <video preload="auto" autoplay loop muted="">
       <source src="http://sawyerfirm.ignitte.com/wp-content/uploads/2015/12/Girl-Riding-In-Car-8-BW.mp4" type="video/mp4">
       <source src="http://sawyerfirm.ignitte.com/wp-content/uploads/2015/12/Girl-Riding-In-Car-8-BW.webm" type="video/webm">
     </video>
     </div>

答案 1 :(得分:4)

你可以使用这个我希望它适合你:)

 This is html code :
 <div class="video-frame">
<video class="video-box" autoplay  poster="video-back.jpg" id="bgvid" loop>
<source src="sample.webm" type="video/webm">
<source src="sample.mp4" type="video/mp4">
</video>
</div>

This is css code :
.video-frame { position:relative;margin:40px auto;width:100%;}
.video-box { position: fixed; top: 50%; left: 50%; min-width: 100%; min-height: 100%; width: auto; height: auto; z-index: -100; transform: translateX(-50%) translateY(-50%); background: url('video-back.jpg') no-repeat; background-size: cover; transition: 1s opacity;}

答案 2 :(得分:0)

object-fit:IE不支持Cover。使用以下库,作为IE的后备:

https://github.com/constancecchen/object-fit-polyfill

答案 3 :(得分:0)

在IE上,将视频的高度设置为自动。

在其他浏览器上:

.video {

    overflow: hidden;
    position: relative;
    width: 100%;
    height: 100%;

    /* HTML video tag */
    &__player, video {

        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        object-fit: cover; /* IE not work */
    }
}

在IE上:

.video {

    overflow: hidden;
    position: relative;
    width: 100%;
    height: 100%;

    /* HTML video tag */
    &__player, video {

        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: auto; /* IE change to auto */
    }
}

和HTML:

<div class="video">
    <video class="video__player" width="400" muted loop>
        <source src="XXX" type="video/mp4">
        Your browser does not support HTML5 video.
    </video>
</div>