Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

jQUERY: Interval doubles?

Featured Replies

doing a bit of jquery to make an image rotator, Got it rotating nicely, however i am now trying to make previous and next buttons. I have encountered an issue, the next button works but doubles the speed of the interval despite clearing the interval?

 

Any ideas?

 

   $(".hero").first().addClass("active");
   var rotate = function () {
       setInterval(function () {
           $(".active").next().addClass("active");
           $(".active").prev().removeClass("active");
           if ($(".active").next().length < 1) {
               $(".hero").first().addClass("active");
               $(".hero").last().removeClass("active");
           };
       }, 5000);
   };

   window.clearInterval(rotate);
   window.setInterval(rotate);

   if ($(".hero").length > 1) {
       $(".hero").append('<div class="previousArrow">prev</div>');
       $(".hero").append('<div class="nextArrow">next</div>');
       $(".nextArrow").click(function () {
           window.clearInterval(rotate);
           window.setInterval(rotate);
           $(".active").next().addClass("active");
           $(".active").prev().removeClass("active");
       });
   }

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.