
jQuery slideshow
By:
cacko on
Apr 25th, 2012 | syntax:
jQuery | size: 0.93 KB | hits: 35 | expires: Never
$(document).ready(function() {
var nextButton = $('#slideshow .next');
var prevButton = $('#slideshow .previous');
var _timeout = 3500
var idx = 0;
var auto = true;
var nItems = $('div.items>div.page').size();
$('div.items').width(nItems * 960);
var slide = function(offset) {
idx = idx +((typeof(offset) == 'undefined') ? 1 : offset);
prevButton.toggle((idx > 0));
nextButton.toggle((nItems - 1 > idx));
$('div.items').animate({
left : -(idx * 960),
opacity : 1
}, 500, function() {
if(auto) {
if(!(nItems > idx + 1)) {
idx = -1;
}
timer = setTimeout(slide, _timeout);
}
});
}
nextButton.show();
var timer = setTimeout(slide, _timeout);
$('#slideshow .navButton').click(function() {
clearTimeout(timer);
auto = false;
slide($(this).hasClass('next') ? 1 : -1);
});
});