Skip to content

Instantly share code, notes, and snippets.

@EpocSquadron
Created January 23, 2012 20:36
Show Gist options
  • Save EpocSquadron/1665416 to your computer and use it in GitHub Desktop.
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.
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