I have a bit of javascript/jQuery which creates a simple slideshow. I’m learning jquery as i go here… and I’m stumped on how to modify this bit of JS to cycle x amount of times before stopping. As of right now it does the slideshow on an infinite loop. Any suggestions? Thanks!
<script>
function slideSwitch() {
var $active = $('#slideshow DIV.active');
if ( $active.length == 0 ) $active = $('#slideshow DIV.item:last');
var $next = $active.next().length ? $active.next()
: $('#slideshow DIV.item:first');
$active.addClass('last-active');
$next.css({opacity: 0.0})
.addClass('active')
.animate({opacity: 1.0}, 1000, function() {
$active.removeClass('active last-active');
});
}
$(function() {
setInterval( "slideSwitch()", 5000 );
});
</script>
Just
clearTimeout()after 5 times: