悬停在视频上时显示内容

showing Content upon hovering on video

我想在悬停视频时显示 class "overlay header" 中的一些内容,例如控件。 比如视频名称和其他元素。

当我在视频上设置悬停 属性 时。它没有反映。

我想规定,将鼠标悬停在叠加层 header 中的内容后,显示并在 5 秒后消失。 有人可以帮我 css 吗? 这是我的 html 代码

<body>
  <div class="video-container">
    <div class="overlay-header"><h1>Joker</h1></div>
    <div class="video-wrapper">
      <video class="video" autoplay controls>
        <source src="../../assets/movies/joker.mp4" type="video/mp4" />
        Your browser does not support HTML5 video.
      </video>
    </div>
  </div>
</body>

这是我的css代码

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial;
  font-size: 17px;
}

video {
  background-color: black;
  outline: none;
  position: fixed;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
}
.video-container video {
  z-index: 0;
}
.overlay-header {
  color: white;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}

如果你想让标题只显示5秒,你需要添加某种形式的JS来添加计时功能。

但是,为了在悬停时获得标题,我在代码笔中添加了 css: https://codepen.io/adamjamesturner/pen/PowMLve

HTML

<body>
  <div class="video-container">
    <div class="video-wrapper">
      <video class="video" autoplay controls>
        <source src="../../assets/movies/joker.mp4" type="video/mp4" />
        Your browser does not support HTML5 video.
      </video>
      <div class="overlay-header"><h1>Joker</h1></div> // By moving to here I can use the sibling selector in CSS
    </div>
  </div>
</body>

CSS

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial;
  font-size: 17px;
}

video {
  background-color: black;
  outline: none;
  position: fixed;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
}
.video-container video {
  z-index: 0;
}
.overlay-header {
  display: none;    // HIDE THE TITLE UNTIL HOVER
  color: white;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}

.video:hover + .overlay-header { ON VIDEO HOVER, DISPLAY THE SIBLING TITLE COMPONENT
  display: block;
}

你可以在 Jquery 中这样做

$(".overlay-header").hide();
$(".video").hover( function(){
$(".overlay-header").show();
setTimeout(function(){
$(".overlay-header").hide();
}, 5000);
})