All Posts by Email, Once a Week

Media Temple logo

CSS-Tricks is brought to you in part by Media Temple, the web hosting that we both use and recommend.

Issue with setInterval and setTimeout

  • # June 27, 2013 at 8:18 am

    Hi, guys

    Here is my script http://codepen.io/Kuzyo/pen/dEtnp , there is setInterval and I want to clearInterval after you click on a button. Everything works if setInterval 500-1000ms, but when I change it on 200 buttonv continues jumps. I read somewhere that setInterval can be rewrite to setTimeout and I wondering if it can fix my problem? Thnaks for reply

    # June 27, 2013 at 9:02 am

    This reply has been reported for inappropriate content.

    It’s because your interval is faster than the animation, so they queue up. Even if you clear the interval, jQuery will keep playing queued up animations until they are all finished.

    Make sure the interval time is at least the total animation time, and check this how to clear the queue: http://api.jquery.com/stop/

    # June 27, 2013 at 9:10 am

    clear the interval and after that add

    $button.stop();

    Edit : @CrocoDillon beat me to it.

    # June 27, 2013 at 10:38 am

    Thanks @CrocoDillon, @pixelgrid fixed with $button.stop(true, true);

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed