Skip to content

Instantly share code, notes, and snippets.

@MrMooky
Forked from zexeder/slick-random.js
Created February 28, 2020 11:18
Show Gist options
  • Save MrMooky/239786f45b3cfe9524592dd7a0010159 to your computer and use it in GitHub Desktop.
Save MrMooky/239786f45b3cfe9524592dd7a0010159 to your computer and use it in GitHub Desktop.
Slick Random Slides
$.fn.randomize = function (selector) {
var $elems = selector ? $(this).find(selector) : $(this).children(),
$parents = $elems.parent();
$parents.each(function () {
$(this).children(selector).sort(function (childA, childB) {
// * Prevent last slide from being reordered
if($(childB).index() !== $(this).children(selector).length - 1) {
return Math.round(Math.random()) - 0.5;
}
}.bind(this)).detach().appendTo(this);
});
return this;
};
$(".slider").randomize().slick();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment