随机排列子元素
$.fn.shuffleChildren = function() {
$.each(this.get(), function(index, el) {
var $el = $(el);
var $find = $el.children();
$find.sort(function() {
return 0.5 - Math.random();
});
$el.empty();
$find.appendTo($el);
});
};
使用
$(".parent-element").shuffleChildren();
查看代码笔
jQuery 随机排列函数 by Chris Coyier (@chriscoyier…