我注意到GIF并不是真的在所有浏览器中都兼容,所以我一直在使用电影。到目前为止一直在寻找。我有一个网站,背景图片是用CSS编写的。我有种感觉,这是行不通的,但我尝试将电影链接起来,就像我要拍摄图像一样,它甚至没有出现。下面是html和CSS。

html

 <section id="slider">
  <div class="container">
    <div class="row">
      <div class="col-md-10 col-md-offset-2">
        <div class="block">
          <h1 class="animated fadeInUp">Need a Network?</h1>
          <p class="animated fadeInUp">Then you are in the right place. We can help Design, Setup, Configure, and Maintain a network that fits your exact needs.</p>
        </div>
      </div>
    </div>
  </div>
</section>


的CSS

#slider {
background: url("../img/") no-repeat;
background-size: cover;
background-attachment: fixed;
background-position: 10% 0%;
padding: 200px 0 280px 0;
position: relative;
}
#slider:before {
content: "";
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
background: linear-gradient(to left, #8b86a3, #322e40);
opacity: 0.8;
}
#slider .block {
color: #E3E3E4;
}
#slider .block h1 {
font-family: 'Roboto', sans-serif;
font-weight: 100;
font-size: 45px;
line-height: 60px;
letter-spacing: 10px;
padding-bottom: 45px;
}
#slider .block p {
font-size: 23px;
line-height: 40px;
font-family: 'Roboto', sans-serif;
font-weight: 300;
letter-spacing: 3px;
}


据我了解,链接视频将不会发生,那么另一种选择是什么?我将如何处理?我需要输入现在仍在显示的文字,并使电影不透明。如果我需要使实际电影本身不透明,则可以这样做。谢谢

可以一起查看网站here

最佳答案

您可以使用以下代码在“需要网络”部分的后面添加视频:


  我替换了视频,并使用JavaScript代码“自动播放”了视频!
  
  如果您认为视频可以在没有JavaScript的情况下自动播放,请将其删除!
  
  我还用iframe标记替换了video标记。
  
  您可以通过更改src=""标记内<source>标记上的<video>属性来替换视频。




function playVideo() {
document.getElementsByClassName('video')[0].play();
}

.video {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
z-index: -2;
object-fit: fill;
}
#slider {
/* Removed the background tags, since there are no image placed in the url of the background tag */
/*background: url("../img/") no-repeat;
background-size: cover;
background-attachment: fixed;
background-position: 10% 0%;*/
padding: 200px 0 280px 0;
position: relative;
}
#slider:before {
content: "";
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
background: linear-gradient(to left, #8b86a3, #322e40);
opacity: 0.8;
z-index: -1;
}
#slider .block {
color: #E3E3E4;
}
#slider .block h1 {
font-family: 'Roboto', sans-serif;
font-weight: 100;
font-size: 45px;
line-height: 60px;
letter-spacing: 10px;
padding-bottom: 45px;
}
#slider .block p {
font-size: 23px;
line-height: 40px;
font-family: 'Roboto', sans-serif;
font-weight: 300;
letter-spacing: 3px;
}

<body onload="playVideo()">
<section id="slider">
  <video class="video" autoplay="autoplay">
    <source src="http://media.w3.org/2010/05/sintel/trailer.mp4" type="video/mp4">
  </video>
  <div class="container">
    <div class="row">
      <div class="col-md-10 col-md-offset-2">
        <div class="block">
          <h1 class="animated fadeInUp">Need a Network?</h1>
          <p class="animated fadeInUp">Then you are in the right place. We can help Design, Setup, Configure, and Maintain a network that fits your exact needs.</p>
        </div>
      </div>
    </div>
  </div>
</section>
</body>

07-24 18:59
查看更多