I want to make this work and be interruptible. There should be 1second fadein, 1second fadeout with 3s delay in between, but during that 3seconds or 1second fadein/fadeout, there maybe another action taking place that should take place -- stop previous action and never complete it. Eg during 3second of showing image, the user wants to go to next/next/next/next, so immediately animation should stop and go to next/next/next/next (multiple user clicks) without ever completing the animation started prior to this.
external calls: SlideShow(1); or SlideShow(-1);, etc
function SlideShow(action) {
slideCount = (slideCount+action) % totalSlides;
slides.eq(slideCount).fadeIn(fadeInAmount);
// add 3 second delay/SetTimeout/etc here
// how should setTimeout be involved here so that it, and the fadein/fadeout are stoppable (without ever continuing)
slides.eq(slideCount).fadeOut(fadeOutAmount,function() {
slideCount = (slideCount+increment) % totalSlides;
SlideShow(0);
});
}
This was the starting point with 1s fadein, 3s delay, 1s fadeout
slides.eq(slideCount).fadeIn(fadeInAmount).delay(fadeDelay).addClass('jqImage').fadeOut(fadeOutAmount,function() {
slideCount = (slideCount+increment) % totalSlides;
SlideShow(0);
});
here is one non-working attempt using setTimeout:
function timerStop() {
if (runningTimer) {
clearTimeout(runningTimer);
runningTimer = 0;
}
}
var runningTimer;
function SlideShow(action) {
// $('body').stop(); slides.eq(slideCount).dequeue(); slides.eq(slideCount).stop();
slideCount=(slideCount+action) % totalSlides;
$('#slideControls').html(
(slideCount+1) + "/" + totalSlides
+ "<br>" + "Delay: " + fadeDelay/1000
+ "<br>" + "Skip: " + increment
);
$('#slideStatusbar').html( slides.eq(slideCount).find('img').attr('src').replace(/^.*[\\\/]/, '') ); // Filename only
//slides.eq(slideCount).fadeIn(fadeInAmount).delay(fadeDelay).addClass('jqImage').fadeOut(fadeOutAmount,function() {
// slideCount < totalSlides-1 ? slideCount+=increment : slideCount=0;
// slideCount = (slideCount+increment) % totalSlides;
// SlideShow(0);
// slides.eq(slideCount).addClass('jqImage');
slides.eq(slideCount).fadeIn(fadeInAmount);
runningTimer=setTimeout(function(){
slides.eq(slideCount).fadeOut(fadeOutAmount,function() {
slideCount = (slideCount + increment) % totalSlides; //slideCount = (slideCount + (action ? action : increment)) % totalSlides;
SlideShow(0);
});
}, 1000);
}
This wasn't an easy one.
It took a couple hours to fix.
The temporary "sandbox" you made for me on your server was really usefull.
I would not have been able to solve the problem without it.
;)
Here is your function now:
I also changed these click handlers:
And here are those handlers:
Some more changes, in your index.html...
I commented out these script calls, which I don't even know what they were supposed to do...
But since I removed them, your page is loading a bit faster AND the strange interval behavior which took me soo long to find magically dissapeared.
I also commented out this jQuery lib call:
Because you were calling this one too. So I move it a couple line up.