Skip to content

Instantly share code, notes, and snippets.

@aar0nTw
Created March 2, 2013 16:39
Show Gist options
  • Save aar0nTw/5071847 to your computer and use it in GitHub Desktop.
Save aar0nTw/5071847 to your computer and use it in GitHub Desktop.
Simple js slideshow
(function(){
var index = 0,
changeTime = 15000,
slides = $(".slide");
var select,
nextSlide,
previousSlide,
interval;
select = function(index){
slides.each(function(idx,ele){
$(ele).removeClass("active");
if(idx === index){
$(ele).addClass("active");
}
});
};
nextSlide = function(){
index = (index>0)?index-1:slides.length-1;
select(index);
};
previousSlide = function(){
index = (index<slides.length-1)?index+1:0;
select(index);
};
$(".left-arrow").on('click', function(){
if(interval){
clearInterval(interval);
interval = setInterval(function(){nextSlide()},changeTime);
}
previousSlide();
});
$(".right-arrow").on('click', function(){
if(interval){
clearInterval(interval);
interval = setInterval(function(){nextSlide()},changeTime);
}
nextSlide();
});
interval = setInterval(function(){nextSlide()},changeTime);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment