When you click next or previous, you must stop the interval and previous animations, namely:
clearInterval(run); $('#slideshow img').stop();
When the attenuation for the next image is complete, you restart the interval ie:
$('#slideshow img:last').fadeIn(1000, function() { run=setInterval("switchSlide()", speed);})
edit: If you press the switch button 10 times within a second. About 20 animations will be performed simultaneously.
edit: If you click on the next or previous one while the image switches (automatically or otherwise) and the fading is already in progress, the fading will occur from almost fading to the complete disappearance of the entire effect in the time interval (so 1 second). At this time, the image will be mostly white.
It is better to set the acceleration during manual switching faster (for example, 300 ms or even less). It will also improve user experience.
edit: here is the fiddle
Here is the code:
var speed = 4000; run = setTimeout("switchSlide()", speed); $(document).ready(function() { $('#caption').html($('#slideshow img:last').attr('title')); $('#previous').click(switchBack); $('#next').click(switchSlide); }); function switchSlide() { clearInterval(run); $('#slideshow img').stop(true,true); var jq=$('#slideshow img'); jq.first().css({'opacity':0}).appendTo('#slideshow').animate({'opacity':1}, 1000, function() { run = setTimeout("switchSlide()", speed); } ); $('#caption').html(jq.last().attr('title')); } function switchBack() { clearInterval(run); $('#slideshow img').stop(true,true); var jq=$('#slideshow img'); jq.last().animate({'opacity':0},1000, function() { $(this).prependTo('#slideshow').css({'opacity':1}); run = setTimeout("switchSlide()", speed);}); $('#caption').html(jq.get(1).title); }
source share