javascript - 如何在鼠标移出时停止 jQuery 悬停函数队列?

标签 javascript jquery html css

我正在为一家公司构建一个关于部分,他们希望在其中以特定方式显示两张图片和一段简短的个人简介。这个想法是,他们的头像将显示在网格中,当您将鼠标悬停在头像上时,图片会发生变化,然后叠加层会下降,然后他们的简短生物会淡出。一旦鼠标离开该部分,同样的事情就会以相反的顺序发生。

我已经用 jQuery 构建了这个,但是我在函数队列方面遇到了问题。如果您快速将鼠标悬停在图像上,以便鼠标在函数队列完成之前离开该部分,它就会全部崩溃。 (跳转到下面的 jsfiddle 示例,只需将鼠标快速滑过图像即可了解我的意思)。

我尝试过以多种不同的方式使用 .stop() 函数,但都没有成功。这是我第一次遇到这个问题,我还没有发现太多关于这个特定问题的方法,所以我想知道是否有更有效的方法来构建它?任何帮助将不胜感激!

这是我的基本 jQuery

$(document).ready(function(){

$("li.member").hover(function(){
        var thisInHover = this;
        $(thisInHover).find("li.member-monster").stop().fadeIn('slow', function(){
            $(thisInHover).find("li.member-overlay").stop().slideDown('slow', function(){
                $(thisInHover).find("li.member-description").stop().fadeIn('slow');
            });
        });

}, function(){

        var thisInHover = this;

        $(thisInHover).find("li.member-description").fadeOut('slow', function(){
            $(thisInHover).find("li.member-overlay").slideUp('slow', function(){
                $(thisInHover).find("li.member-monster").fadeOut('slow');
            });
        }); 
    });
});

这是我现在拥有的工作示例 --> http://jsfiddle.net/jumplikeaginger/6pzjh4sn/

最佳答案

也将 stop() 添加到 hoverout:

http://jsfiddle.net/6pzjh4sn/1/

$(document).ready(function(){

    $("li.member").hover(function(){
            var thisInHover = this;
            $(thisInHover).find("li.member-monster").stop().fadeIn('slow', function(){
                $(thisInHover).find("li.member-overlay").stop().slideDown('slow', function(){
                    $(thisInHover).find("li.member-description").stop().fadeIn('slow');
                });
            });

    }, function(){

            var thisInHover = this;

            $(thisInHover).find("li.member-description").stop().fadeOut('slow', function(){
                $(thisInHover).find("li.member-overlay").stop().slideUp('slow', function(){
                    $(thisInHover).find("li.member-monster").stop().fadeOut('slow');
                });
            });

        }); 

});

关于javascript - 如何在鼠标移出时停止 jQuery 悬停函数队列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27987161/

相关文章:

javascript - Selenium - {[[PromiseStatus]] : "pending"} has no method 'indexOf'

php - 接下来要学习什么才能将额外功能应用于 CMS 模板?

javascript - react img 标签问题与 url 和类

javascript - $ ("p").each(function (){}) vs for( p in $ ("p") 返回不同的段落数值

php - jQuery,在 ul 中 foreach div

javascript - 如何为低带宽连接禁用 jquery include

javascript - React 父级将 props 传递给子级会导致无限循环

html - 在 bootstrap 4 中使用 justify-content-center 打破标签

html - 在 CSS 中创建一个无样式类

html - 何时使用 vh 和最小高度 :100vh