Created
May 8, 2013 08:53
-
-
Save kamilogorek/5539162 to your computer and use it in GitHub Desktop.
Carousel iteration logic
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
// Items number | |
var items = elem.length; | |
// Any element containing data about current index | |
var current = elem.data('current'); | |
var next; | |
// Button directory | |
var direction = elem.data('dir'); | |
// Logic for calculating next items index | |
if (direction === 'next') { | |
if (current === --items) { | |
next = 0; | |
} else { | |
next = ++current; | |
} | |
} else if (direction === 'prev') { | |
if (current === 0) { | |
next = --items; | |
} else { | |
next = --current; | |
} | |
} | |
// Update element data about current index | |
elem.data('current', next); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment