本文介绍了jQuery停止淡入淡出效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://jsfiddle.net/sJFLq/1/

当您在div上悬停时,我想要的是一种鼠标尾随的效果.但是,如果将鼠标悬停太快几次然后停止,效果将自行重复.

what I want is a sort of a mouse-trail effect, when you hover up or down the divs. But if you hover the mouse too fast a few times and then stop, the effect keeps repeating on it's own.

我该如何解决?我想我需要某种出队的东西,例如带有animate选项,但是需要使用fadeTo函数.有任何想法吗?

How can I solve this? i think i need some kind of a de-queue thing like with animate option, but for the fadeTo function. any ideas?

推荐答案

您可以使用.stop方法停止以前的动画.如果将true作为参数传递,它还将清除排队的动画.

You can use the .stop method to stop previous animations. If you pass in true as an argument, it will also clear queued animations.

如果我正确理解了您要寻找的内容,那么您想要的就是这个(您说过您想要鼠标跟踪",我指的是您不希望先前的动画停止播放)鼠标离开该元素后,因此只需调用一次.stop):

If I've understood what you're looking for correctly, then what you want is this (you said you want a "mouse trail", which I'm taking to mean you don't want the previous animation to stop as soon as the mouse leaves that element, hence only the one call to .stop):

$(".test").mouseover(function(e){
    $(this).stop(true).fadeTo(200,1);
}).mouseout(function(e){
    $(this).fadeTo(200,0.3);
});

您可以看到在此处运行.

这篇关于jQuery停止淡入淡出效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 17:42