/    Sign up×
Community /Pin to ProfileBookmark

Stop slideshow script on last image

I’ve got this short script and jQuery to make a slideshow of 5 images with fade transitions but I don’t know how to get it to stop on the last slide. Does anyone know how to do this?

function slideSwitch() {
var $active = $(‘#slideshow IMG.active’);

if ( $active.length == 0 ) $active = $(‘#slideshow IMG:last’);

var $next = $active.next().length ? $active.next()
: $(‘#slideshow IMG:first’);

$active.addClass(‘last-active’);

$next.css({opacity: 0.0})
.addClass(‘active’)
.animate({opacity: 1.0}, 700, function() {
$active.removeClass(‘active last-active’);
});
}

$(function() {
setInterval( “slideSwitch()”, 1000 );
});

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @andrewjhermiz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...