Created
September 4, 2017 09:28
-
-
Save zexeder/621f6a795a51f7c2da9236fa8ccd69f0 to your computer and use it in GitHub Desktop.
Slick Random Slides
This file contains hidden or 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
Works great, Thank you!