I have a well functioning div slider: http://jsfiddle.net/UqSFr/2/
The basic function is this:
$("#NextButton").click(function(e) {
e.preventDefault();
if ( $("#h_wrapper").is(':not(:animated)') && $("#NextButton").is(':not(:animated)') ) {
var newMargin = CurrentMargin() - SlideWidth;
$("#h_wrapper").animate({ marginLeft: newMargin }, SlideSpeed, function () { SetNavigationDisplay() });
}
});
In addition to the click functionality, I want to add a timer so if not clicked in 5 seconds, it should move to the next.
The timer should be reset on click
When the end is reached it must go to the first div (marginLeft = 0)
Have a look at this code
It’s pretty easy. By saving the index it’s easier to calculate next and previous offset. Splitting the entire animation into a separate function, the code doesn’t gets easier to read and understand, but easier to call as well.