首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jquery fadeOut问题

Jquery fadeOut问题
EN

Stack Overflow用户
提问于 2014-08-05 14:58:30
回答 2查看 39关注 0票数 1

这只是一个增加我对Jquery知识的测试,请告诉我为什么当我悬停在#box5对象上时,它不止一次地显示白色和蓝色的框。

代码语言:javascript
复制
$(document).ready(function () {
    $("#Box5").hide();
    $("#Button").click(function () {
    $("#Button").val("Show");
    $("#BoxArea").toggle();
    $("#Box5").toggle();
});
$("#Box5").hover(function () {
    $(this).css("background-color", "green");
    $(this).fadeOut(function () {
        $(this).css("background-color", "red");
        $(this).show(100);
        $(this).fadeOut(function () {
            $(this).css("background-color", "white");
            $(this).show(100);
            $(this).fadeOut(function () {
                $(this).css("background-color", "blue");
                $(this).show(100);
            });
         });
      });
   });
});

http://jsfiddle.net/45X2L/3/

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-08-05 15:12:26

.hover()方法为mouseentermouseleave事件绑定处理程序。 有关更多细节,请参见.mouseenter().mouseleave()的讨论。

将事件更改为mouseenter,它将正常工作。

代码语言:javascript
复制
$(document).ready(function () {
    $("#Box5").hide();
    $("#Button").click(function () {
        $("#Button").val("Show");
        $("#BoxArea").toggle();
        $("#Box5").toggle();
    });
    $("#Box5").mouseenter(function () {
        $(this).css("background-color", "green");
        $(this).fadeOut(400, function () {
            $(this).css("background-color", "red");
            $(this).show(400);

            $(this).fadeOut(400, function () {
                $(this).css("background-color", "white");
                $(this).show(400);

                $(this).fadeOut(400, function () {
                    $(this).css("background-color", "blue");
                    $(this).show(400);

                });
            });

        });
    });


});
票数 1
EN

Stack Overflow用户

发布于 2014-08-05 15:10:46

我认为,当您调用fadeOut #Box5并显示它时,它就会显示在鼠标指针下面,从而触发另一个hover事件,因为动画引导该框让指针进入其区域。

在悬停处理程序的开头添加一个alert将让您明白我的意思。

我认为解决这个问题的唯一方法是在执行fadeOut/fadeIn操作时关闭悬停处理程序,然后在完成时重新打开它。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25142042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档