将我附加到另一个的 div 随机化 [英] Randomize the divs that I append into another one

查看:26
本文介绍了将我附加到另一个的 div 随机化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我所拥有的:

$(function(){
    $('.apple').appendTo('.container');
});

现在,假设我有 20 个不同的 div,类名为 .apple.

Now, lets say I have 20 different divs with class name .apple.

我怎样才能让它们Container随机附加到Container中?所以每次我加载页面时,顺序都会不同.

How can I have them append into Container randomly? So every time that I load the page the order would be different.

提前谢谢你!

推荐答案

$.when($(".apples"), [])
    .done(function (data, apples) {
    $.each(data, function (k, v) {
        setTimeout(function () {
            apples.push(v);
            if (apples.length === data.length) {
                $(apples).appendTo(".container")
            };
        }, 1 + Math.floor(Math.random() * 5));
    });
});

jsfiddle http://jsfiddle.net/guest271314/d4p39/

这篇关于将我附加到另一个的 div 随机化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆