Created
September 28, 2015 17:28
-
-
Save stnadmin/3227436b5a9e4c946253 to your computer and use it in GitHub Desktop.
Carousel JS script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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