For more information about this project, follow this link.
Created
September 23, 2012 02:06
-
-
Save rnmp/3768546 to your computer and use it in GitHub Desktop.
DATA-COLUMNS
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
// DATA-COLUMNS by Rolando Murillo (@rnmp) | |
// and Giorgio Leveroni (@ppold) | |
var grids = document.querySelectorAll('[data-columns]'); | |
[].forEach.call(grids, function(grid) { | |
var columns = grid.dataset.columns, | |
columnClass = '_col', | |
itemClass = '_item', | |
elements = []; | |
for (var i = columns - 1; i >= 0; --i) { | |
elements.push(grid.querySelectorAll('.'+itemClass+':nth-child('+columns+'n-'+i+')')); | |
} | |
elements.forEach(function(columnElements) { | |
var column = document.createElement('div'); | |
column.classList.add(columnClass); | |
Array.prototype.forEach.call(columnElements, function(element) { | |
column.appendChild(element); | |
}); | |
grid.appendChild(column); | |
}); | |
}); |
Actually storing the forEach function in a variable is the fastest (using the same link you mentioned).
P.S. I'll implement the responsive support and the addition/deletion of content next week.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[].forEach
is faster thanArray.prototype.forEach
according to: http://jsperf.com/foreach-vs-array-prototype-foreach