Last active
December 13, 2015 17:18
-
-
Save matthewsimo/4946562 to your computer and use it in GitHub Desktop.
Function to return array groups with each group consisting of a certain min size of elements of a matching selector
This file contains hidden or 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
| findGroups = function(selector, size) { | |
| var groups = []; var group = []; | |
| $(selector).each(function(i, v){ | |
| group.push(v); | |
| if(group.length === size) { | |
| groups.push(group); | |
| group = []; | |
| } | |
| }); | |
| if(group.length !== 0) | |
| groups.push(group); | |
| return groups; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you want to get groups of 3 for all items matching the '.article-grid .article' selector:
If you were going to use this with matchH:
Of course you'd want to set columns intelligently based on the breakpoint...