gpt4 book ai didi

jquery - 使用Jquery悬停播放音频

转载 作者:行者123 更新时间:2023-12-02 23:03:09 24 4
gpt4 key购买 nike

我有一个音频文件,并且希望它在光标悬停在放置音频文件的div时立即播放。

出于任何原因,它仅适用于单击功能,而不适用于悬停/鼠标功能。

这正在工作:

$(".interview").on("click",function(){
$(this).find("#audio")[0].play();
});

这不起作用:
$(".interview").on("hover",function(){
$(this).find("#audio")[0].play();
});

最佳答案

从jQuery 1.8开始不推荐使用Hover。 ref Jquery on hover not working

 $(".interview").hover(function(){
$(this).find("#audio")[0].play();
});

(或)使用 mouseenter事件ref https://api.jquery.com/mouseenter/

$(document).on('mouseenter','.interview',function(){
alert(1)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<div class="interview">hover me</div>

关于jquery - 使用Jquery悬停播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55949055/

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