Home >Web Front-end >JS Tutorial >Detailed explanation of the difference between stop() and :is(:animated) in jquery
stop(true,true):
means to stop the ongoing animation of the matching element and jump to the end state, clearing the unfinished animationqueue . Often used to "solve the problem of inconsistent animation effects and cursor movements caused by moving the cursor in and out too quickly"!
jQuery stop() method
jQuery stop() method is used to stop animations or effects before they are completed.
The stop() method works with all jQuery effects Functions, including slides, fades, and custom animations.
Syntax
$(selector).stop(stopAll,goToEnd);The optional stopAll parameter specifies whether the animation queue should be cleared. The default is false, which only stops active animations, allowing any queued animations to execute backwards.
The optional goToEnd parameter specifies whether to complete the current animation immediately. The default is false.
So, by default, stop() will clear the current animation specified on the selected element.
The following example demonstrates the stop() method without parameters:
$("#stop").click(function(){ $("#panel").stop(); });
:is(":animated") :animated is the jQ selector that selects all animated elements
Determine whether the element is in an animated state. It is often used when "continuously clicking the previous/next button and only responding to the user's first click action".
if(!$("#lunbolist li").is(":animated")){ $("#lunbolist li").filter(".on").hide(); $("#lunbolist li").eq(currentindex).fadeIn(100).addClass("on").siblings().removeClass("on"); $(this).addClass("on").siblings().removeClass("on"); }
The above is the detailed content of Detailed explanation of the difference between stop() and :is(:animated) in jquery. For more information, please follow other related articles on the PHP Chinese website!