Skip to content

Instantly share code, notes, and snippets.

@rnmp rnmp/ABOUT.md
Created Sep 23, 2012

Embed
What would you like to do?
DATA-COLUMNS

For more information about this project, follow this link.

// 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);
});
});
@rnmp

This comment has been minimized.

Copy link
Owner Author

rnmp commented Oct 29, 2012

[].forEach is faster than Array.prototype.forEach according to: http://jsperf.com/foreach-vs-array-prototype-foreach

@ppold

This comment has been minimized.

Copy link

ppold commented Feb 21, 2013

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
You can’t perform that action at this time.