Skip to content

Instantly share code, notes, and snippets.

@magadanskiuchen
Created November 7, 2012 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magadanskiuchen/4030291 to your computer and use it in GitHub Desktop.
Save magadanskiuchen/4030291 to your computer and use it in GitHub Desktop.
(function () {
var slider = $('.stories-slider');
var list = slider.find('#carousel');
var items = list.find('> .slide');
var thumbs = slider.find('.thumb');
var duration = 500;
var current = 0;
list.css({ width: items.length * 100 + '%' });
items.css({ width: (1/items.length) * 100 + '%' });
function slideTo(index) {
if (index > -1 && index < items.length) {
thumbs.removeClass('selected').eq(index).addClass('selected');
list.animate({ left: '-' + (index*100) + '%' }, duration, function () {
current = index;
});
}
}
function slidePrev() {
if (current) {
var prev = current - 1;
} else {
var prev = items.length - 1;
}
slideTo(prev);
}
function slideNext() {
if (current + 1 < items.length) {
var next = current + 1;
} else {
var next = 0;
}
slideTo(next);
}
thumbs.click(function () {
slideTo($(this).index());
}).first().click();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment