如何在CSS中用视频源替换图像源

时间:2018-06-21 14:28:26

标签: html css video parallax

嗨,我需要一点帮助,以将视频源替换为视频源,以使其成为视差。

CSS代码

.parallax {
    /* The image used */
    background-image: url("img/cour2.jpg");

    /* Set a specific height */
    min-height: 1000px; '
    width:100%;

    /* Create the parallax scrolling effect */
    background-attachment: fixed;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}

我的主要任务是在标题中添加视频背景,并使其成为视差。 Link to page here 我必须用视频背景替换此图像,而不会影响视差效果。有可能这样做吗?

请帮助我,谢谢你

1 个答案:

答案 0 :(得分:0)

嗨Tamilselvan,

如果我正确理解您的问题,并且视频应在具有视差效果的背景下,则解决方案在下面的代码段中。据我所知,CSS background规则是无法做到的。


您应该在单独的video中向视频和页面内容添加带有URL的HTML5 div标签。全部都可以放在一个容器中。 #backgroundVideo遵循CSS规则width: 100%;height: 100%;以使其适合其容器。

#container {
  position: relative;
  width: 100%;
  height: 100%;
}

#content {
  position: absolute;
  top: 0;
}

#backgroundVideo {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
}
<div id="container">
  <video autoplay muted loop id="backgroundVideo">
    <source src="https://i.imgur.com/bCdy2XU.mp4" type="video/mp4">
    Your browser does not support HTML5 video.
  </video>
  <div id="content">
    What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type
    specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently
    with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using
    Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default
    model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like). Where does it come from? Contrary
    to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of
    the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et
    Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section
    1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by
    English versions from the 1914 translation by H. Rackham. Where can I get some? There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't
    look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as
    necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore
    always free from repetition, injected humour, or non-characteristic words etc.
  </div>
</div>


Link to the full snippet用于此答案-您可以在那里尝试。

W3S site,很好的示例是如何在后台设置视频。


干杯