【发布时间】:2016-09-19 13:29:12
【问题描述】:
我有一个video 元素。当用户将鼠标悬停在允许他们暂停/播放和静音/取消静音的视频上时,我希望出现一些控制按钮。这是我的 html、CSS 和 jQuery:
HTML
<video autoplay muted>
<source src="<?=get_template_directory_uri()?>/video/bfvideo.mp4" type="video/mp4">
<img src="<?php the_field('hero_image'); ?>" class="hero-text img-res" alt="<?php the_field('hero_image_alt_text'); ?>"/>
</video>
<div class="videoMute videoButton">M</div>
<div class="videoPause videoButton">P</div>
js
heroVideo.hover(
function() {
// In
console.log('In');
$('.videoButton').fadeIn(100);
//heroVideo.prop('muted','');
},
function () {
// Out
console.log('Out');
$('.videoButton').fadeOut(100);
//heroVideo.prop('muted','true');
}
);
CSS
.videoButton {
background: #ccff00;
display: inline-block;
height: 50px;
width: 50px;
position: absolute;
z-index:9999;
bottom:50px;
text-align:center;
cursor:pointer;
display:none;
}
.videoMute {
left:50px;
}
.videpPause {
left:250px;
}
当我将鼠标悬停在视频内外时,按钮会根据需要出现和消失,但是当我将鼠标悬停在按钮上时,从技术上讲,我是在视频上悬停,因为我是在按钮上悬停(虽然我' m 仍然在屏幕上的视频区域中)。因此,当我将鼠标悬停在按钮上时,它们就会消失。
有没有办法防止这种情况发生?无论我的光标是否实际上在该元素上,我都希望按钮在我处于视频区域时出现。
【问题讨论】:
-
如果只需要暂停/播放、静音/音量、全屏;您可以启用浏览器的默认 HTML5 播放器控件。
-
@pol - 当然,但它们有点难看。我试图让一些更符合网站布局的内容(ps。我知道当前的 CSS 远非漂亮 - 这只是我在解决这个问题后美化它之前的测试布局)。
-
如果您将视频和按钮包装在同一个容器 div 中并在容器上使用悬停事件,它将更轻松地解决您的问题。
-
@klikas - 啊,当然!如果您想将其添加为答案,我会接受。
-
@BFWebAdmin 谢谢,完成了 :)
标签: javascript jquery html css hover