-
-
Save MrMooky/239786f45b3cfe9524592dd7a0010159 to your computer and use it in GitHub Desktop.
Slick Random Slides
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.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