Skip to content

Instantly share code, notes, and snippets.

@zexeder
Created September 4, 2017 09:28
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save zexeder/621f6a795a51f7c2da9236fa8ccd69f0 to your computer and use it in GitHub Desktop.
Save zexeder/621f6a795a51f7c2da9236fa8ccd69f0 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();
@maejok-xx
Copy link

thank you for this!

@hborrelli1
Copy link

Works great, Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment