How do you cancel a jQuery fadeOut() once it has started?

后端 未结 3 1386
迷失自我
迷失自我 2020-12-18 17:59

I have a basic div element to represent a message that I show for a few seconds and then fade it out using

$(\'#message\').fadeOut(5000);

I

3条回答
  •  臣服心动
    2020-12-18 18:28

    In my case stop() merely didn't work at least in Firefox, after searching I figured out that It should be stop(true, true):

    $('#message').mouseover(
        function () {
             $(this).stop(true, true).fadeOut();
        }
    );
    

    stop(): Stops the currently-running animation on the matched elements.

    or even you can use finish() instead:

    $('#message').mouseover(
        function () {
             $(this).finish().fadeOut();
        }
    );
    

    but there is a side effect about finish(), it stops all other running animations too.

    finish(): Stops the currently-running animation, remove all queued animations, and complete all animations for the matched elements.

    Read more here.

提交回复
热议问题