Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Created December 19, 2022 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nocodesupplyco/3de6b7a8081682c72c7747a4b564c8e9 to your computer and use it in GitHub Desktop.
Save nocodesupplyco/3de6b7a8081682c72c7747a4b564c8e9 to your computer and use it in GitHub Desktop.
Random Shuffle Sort CMS Items
$.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