June 6, 201214 yr 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