-
-
Save nocodesupplyco/3de6b7a8081682c72c7747a4b564c8e9 to your computer and use it in GitHub Desktop.
Random Shuffle Sort CMS Items
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
$.fn.shuffle = function() { | |
$.each(this.get(), function(index, el) { | |
var $el = $(el); | |
var $find = $el.children(); | |
var i = $find.length, k , temp; | |
while(--i > 0) { | |
k = Math.floor(Math.random() * (i+1)); | |
temp = $find[k]; | |
$find[k] = $find[i]; | |
$find[i] = temp; | |
} | |
$el.empty(); | |
$find.appendTo($el); | |
}); | |
}; | |
// Element you want to target and shuffle on page load | |
$(function() { | |
$(".collection-list").shuffle(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment