视频背景不能在Safari上正常播放

Video Background not playing properly on Safari

本文关键字:常播放 播放 背景 不能 Safari 视频      更新时间:2023-09-26

视频背景在Safari上不能正常播放。它显示在屏幕的右下方,看起来不太好。

这是链接。

下面是HTML代码:

<video autoplay  poster="" id="bgvid" loop>
  <!-- WCAG general accessibility recommendation is that media such as background video play through only once. Loop turned on for the purposes of illustration; if removed, the end of the video will fade in the same way created by pressing the "Pause" button  -->
<source src="http://devjentri.com/wp-content/uploads/2015/09/deW_vid_final_.webm" type="video/webm">
<source src="http://devjentri.com/wp-content/uploads/2015/09/deW-vid-final-.mov" type="video/mp4">
</video>
CSS代码:

video { 
    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-size: cover;
    transition: 1s opacity;
}

您需要将供应商前缀版本的转换添加到您的CSS规则中:

-webkit-transform: translateX(-50%) translateY(-50%);
完整的规则应该是这样的:
video { 
    position: fixed;
    top: 50%;
    left: 50%;
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    z-index: -100;
    -webkit-transform: translateX(-50%) translateY(-50%);
    transform: translateX(-50%) translateY(-50%);
    background-size: cover;
    transition: 1s opacity;
}