gpt4 book ai didi

css - 如何在 div 悬停时隐藏视频?

转载 作者:行者123 更新时间:2023-11-28 10:08:02 26 4
gpt4 key购买 nike

我想在 div 悬停时隐藏视频,但我似乎无法让它工作

目前“live_video”类位于顶部,“eat_video”位于下方。我想在悬停“video_hover”类时隐藏“live_video”的显示

我想要实现的是堆叠 2 个全屏视频,但是当您将鼠标悬停在浏览器窗口右侧 50% 的位置时,它会隐藏顶部视频并显示下方的视频

为什么 .right_hover:hover .live_video {display: none;} 不起作用?

 <div class="live_video">
<video muted class="video" autoplay="autoplay" loop="loop" preload="auto">
<source src="NM_Web_Live_Vid_v1_1_1.mp4" type="video/mp4" >
</video>
</div>

<div class="eat_video">
<video muted class="video" autoplay="autoplay" loop="loop" preload="auto">
<source src="NM_Web_Live_EatPlay_v1_1_1.mp4" type="video/mp4" >
</video>
</div>

CSS

.video_hover {
width: 50%;
height: 100vh;
position: absolute;
right: 0;
top: 0;
z-index: 99;
cursor: pointer;
}

.eat_video {
position: absolute;
width: 100%;
height: 100vh;
top: 0;
z-index: -1;
}

.video_hover:hover .live_video {
display: none;
}

最佳答案

要使 .video_hover:hover .live_video 生效,有一些基本要求 - 主要要求是具有类 video_hover 的元素(和子 live_video) 存在于文档中。

要实现您想要的效果,您可以对 CSS/HTML 应用以下更改:

/* Style video containers to occupy full client area of browser */
.video_hover {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
cursor: pointer;
}
.video_hover video {
display:block;
width: 100%;
height: 100%;
}

/* Define (hidden) pseudo element that will catch hover interactions
to control the visiblity of respective video elements */
.video_hover::before {
content:"";
display:block;
width:50%;
height:100%;
position: absolute;
top: 0;
z-index:100;
}
/* Specify placement of each pseudo element to occupy each side of the
client area */
.live_video::before {
right: 0;
}
.eat_video::before {
left: 0;
}

/* Eat video hidden when hovering not over right half of screen */
.eat_video video {
visibility:hidden;
}

/* When live video (or it's pseudo element) is hovered, "hide" the
video */
.live_video:hover video {
visibility:hidden;
}
/* When live video (or it's pseudo element) is hovered, "show" the
next eact_video video */
.live_video:hover + .eat_video video {
visibility:visible;
}
<!-- Add video_hover to class list -->
<div class="live_video video_hover">
<video muted class="video" autoplay="autoplay" loop="loop" preload="auto">
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4" >
</video>
</div>
<!-- Add video_hover to class list -->
<div class="eat_video video_hover">
<video muted class="video" autoplay="autoplay" loop="loop" preload="auto">
<source src="https://www.fbdemo.com/video/video/demo.mp4" type="video/mp4" >
</video>
</div>

关于css - 如何在 div 悬停时隐藏视频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57881965/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com