Created
October 28, 2014 16:23
-
-
Save lutzissler/18c58d8fd3b600adf97a to your computer and use it in GitHub Desktop.
Little jQuery plugin for spreading, or “partitioning“, elements across several parent elements. Called to create `n` partitions, the plugin wraps the selected elements at positions `c`, `n+c`, `2n+c`, `3n+c`, … into “wrapper” element for all `c` within `1`…`n`.
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
(function ($) { | |
$.fn.partition = function(options) { | |
options = $.extend({ | |
count: false, | |
wrapper : '<div>' | |
}, options || {}); | |
var elems = $(this), | |
len = pos = 0; | |
for (var i = 0; i < options.count; i++) { | |
var sel = elems.filter(":nth-child(" + (options.count - i) + "n)"); | |
sel.wrapAll(options.wrapper); | |
elems = elems.not(sel); | |
} | |
return elems; | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment