Created
January 23, 2012 20:36
-
-
Save EpocSquadron/1665416 to your computer and use it in GitHub Desktop.
Javascript to turn a list into pages with the elements displaced by one at a time -- with wrapping. Thought it was useful, then it wasn't. Maybe someday.
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
var list = target.find('li'), | |
listLen = list.length, | |
newDivs = ''; | |
for (var i = 0; i < listLen; i++) { | |
newDivs += '<div>'; | |
var iLeft = listLen - i, | |
// Simulate wrapping with slice | |
listSlice1 = list.slice(i + 1, i + 4), | |
listSlice2 = list.slice(0, (listLen - iLeft)); | |
// Put the pices together into listSlice1 | |
$.merge(listSlice1,listSlice2); | |
//Add to the newDivs | |
listSlice1.each(function() { | |
newDivs += '<li>' + this.innerHTML + '</li>'; | |
}); | |
newDivs += '</div>'; | |
} | |
// Replace original list with the new divs | |
target.html(newDivs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment