随机播放jQuery选择

Fez*_*sta 2 javascript jquery

我试图改变jQuery选择的顺序,而不是洗涤DOM中的元素.

我需要随机选择以随机顺序为每个元素添加一个类,这就是我的代码应该是这样的:

$(".item").shuffle().each(function (i, element) {
    $(element).delay(i * 100).queue(function (next) {
        $(this).addClass("shown");
        next();
    });
});
Run Code Online (Sandbox Code Playgroud)

有人可以帮我找到shuffle()我需要的功能吗?

ade*_*neo 6

Array.shuffle这个答案中借用了这个方法,并将其变成了一个jQuery插件

$.fn.shuffle = function(){
    for(var j, x, i = this.length; i; j = Math.floor(Math.random() * i), x = this[--i], this[i] = this[j], this[j] = x);
    return this;
};
Run Code Online (Sandbox Code Playgroud)

小提琴