nicinabox / superslides

A fullscreen, hardware accelerated slider for jQuery.
http://archive.nicinabox.com/superslides
MIT License
1.51k stars 443 forks source link

Timer not reseting if slide is manually moved with next / prev #319

Open sam-pudle opened 9 years ago

sam-pudle commented 9 years ago

Ive set the slider to fade every 5000ms, if i count 3 seconds and then forward the slider manually using

$('a.next').click(function () { $slides.data('superslides').animate('next'); });

The next slide only lasts for 2000ms before moving on, it would seem the timer isnt resetting when the slide is manually moved.

ArhamAliQureshi commented 9 years ago

You haven't told the location of timer function. If you are using setInteval then you have to store the reference of that interval in a variable. On the next or previous button click you must clear previous interval and recall setInterval function.

For example

var myVar = setInterval(function(){ myTimer() }, 1000);

$('a.next').click(function (){ myStopFunction(); myVar = setInterval(function(){ myTimer() }, 1000); });

function myTimer() { var d = new Date(); var t = d.toLocaleTimeString(); document.getElementById("demo").innerHTML = t; }

function myStopFunction() { clearInterval(myVar);
}