Skip to content

Instantly share code, notes, and snippets.

@stnadmin
Created September 28, 2015 17:28
Show Gist options
  • Save stnadmin/3227436b5a9e4c946253 to your computer and use it in GitHub Desktop.
Save stnadmin/3227436b5a9e4c946253 to your computer and use it in GitHub Desktop.
Carousel JS script
$(function () {
"use strict";
var root = $('html.onecol #pos-banner .moduletable-carousel'),
next = $('<div class="carousel-next"></div>'),
prev = $('<div class="carousel-prev"></div>'),
perPage = 4,
page = 0,
window = $('<div class="carousel-window"></div>'),
shuttle = $('<div class="carousel-shuttle"></div>'),
frames = $('a', root).detach();
$('table', root).remove();
frames.appendTo(shuttle);
shuttle.appendTo(window);
window.appendTo(root);
next.appendTo(root);
prev.appendTo(root);
function showPage(num) {
shuttle.animate({
left: (num * perPage * frames.first().outerWidth(true)) * -1
});
}
next.click(function () {
page += 1;
if (page > (Math.ceil(frames.length / perPage) - 1)) {
//page = (Math.ceil(frames.length / perPage) - 1);
page = 0;
}
showPage(page);
});
prev.click(function () {
page -= 1;
if (page < 0) {
//page = 0;
page = (Math.ceil(frames.length / perPage) - 1);
}
showPage(page);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment