jQuery - fadeIn(),fadeOut(),animate(),stop()和闪烁

Wor*_*sor 3 jquery fadeout fadein jquery-animate

当"悬停"触发此代码时:

jQuery('#test').animate({opacity: 1},300);
Run Code Online (Sandbox Code Playgroud)

并且用户徘徊并且非常快速地停止"#test"项目长时间闪烁(当然,不透明度在悬停时被动画为1并且在取消悬停时被动画为0).

添加stop()总是对我有用:

jQuery('#test').stop().animate({opacity: 1},300);
Run Code Online (Sandbox Code Playgroud)

关键是我必须使用fadeIn()和fadeOut(),我不知道在这种情况下如何避免闪烁?

实例:http://jsfiddle.net/caHq5/(将指针从黑暗方块快速移动到背景,然后移动到正方形,然后移动到背景等等).stops()什么都不做.

aus*_*lis 5

这是你追求的效果吗?

jQuery(document).ready(function() {    
    jQuery('#container').hover(function(){
        jQuery('#wrong').stop().fadeTo(200,1);
            },function() {
        jQuery('#wrong').stop().fadeTo(200,0);
            });
});
Run Code Online (Sandbox Code Playgroud)

如果你真的希望元素在褪色后被隐藏,而不是只是看不见:

jQuery(document).ready(function() {    
    jQuery('#container').hover(function(){
        jQuery('#wrong').stop().show().fadeTo(200,1);
            },function() {
        jQuery('#wrong').stop().fadeTo(200,0, function() {$(this).hide()});
            });
});
Run Code Online (Sandbox Code Playgroud)