When I hover over what I want fading in and out too many times, then it keeps repeating itself. Even when I stop hovering it. How can I stop this?
$(".featured").hover(function(){
$(this).f开发者_运维问答ind("h3").fadeToggle(800);
});
You need to call .stop()
$(this).find("h3").stop(true, true).fadeToggle(800);
Parameters indicate: clearQueue, jumpToEnd
This will almost immediately stop the current animation. To have a more smooth stopping, you should call .stop(true, false)
Another way I can think of is to check whether the element is animated or not:
$(".featured").hover(function(){
var $h3 = $(this).find('h3');
if(!$h3.is(':animated') )
$h3.fadeToggle(800);
});
Reference: .stop(), :animated selector
精彩评论