gpt4 book ai didi

javascript - 停止多个悬停事件的传播

转载 作者:行者123 更新时间:2023-12-02 16:29:15 25 4
gpt4 key购买 nike

我的主页包含多个框。

在每个框中,当鼠标悬停 in 或 out 时,标题会消失并显示内容。

效果很好。

问题在于,当鼠标在短时间内悬停在多个框上时,情况会变得一团糟。

$( ".views-field-wrapper" ).each(function(){         
$( this ).hover(function() {
$( "#front_panel",this ).fadeOut(400);
$( "#back_panel",this ).delay(500).fadeIn(1000);
}, function(){
$( "#back_panel",this ).fadeOut(400);
$( "#front_panel",this ).delay(500).fadeIn(1000);
});
});

当鼠标悬停在另一个框上时,如何停止之前的鼠标悬停 react ?

编辑:

我的初始代码:http://jsfiddle.net/tz3d6ct6/

Kumar 的代码与 jquery > 1.6 完美配合(我必须使用 jquery1.4)http://jsfiddle.net/hrkf5p7w/

最佳答案

尝试使用stop()并且无需使用循环来绑定(bind)悬停事件

$( ".views-field-wrapper" ).hover(function() { // no need to use each loop
$( "#front_panel",this ).stop(true).fadeOut(400);
$( "#back_panel",this ).delay(500).fadeIn(1000);
}, function(){
$( "#back_panel",this ).stop(true).fadeOut(400);
$( "#front_panel",this ).delay(500).fadeIn(1000);
});

尝试不使用 delay() 之类的,

$(".views-field-wrapper").hover(function () { // no need to use each loop
$("#front_panel", this).stop(true).fadeOut(400);
$("#back_panel", this).fadeIn(1000);

}, function () {
$("#back_panel", this).stop(true).fadeOut(400);
$("#front_panel", this).fadeIn(1000);
});

$(".views-field-wrapper").hover(function () { // no need to use each loop
$("#front_panel", this).stop(true).fadeOut(400);
$("#back_panel", this).fadeIn(1000);

}, function () {
$("#back_panel", this).stop(true).fadeOut(400);
$("#front_panel", this).fadeIn(1000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='views-field-wrapper type-t nodetype-t'>
<div id='front_panel'>title</div>
<div style='display:none' id='back_panel'>teaser</div>
</div>

关于javascript - 停止多个悬停事件的传播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28453320/

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