随机化我追加到另一个的div [英] Randomize the divs that I append into another one
本文介绍了随机化我追加到另一个的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我所拥有的:
$(function(){
$('.apple').appendTo('.container');
});
现在,假设我有20个不同的div类名。 apple 。
Now, lets say I have 20 different divs with class name .apple.
如何让它们随机附加到容器 ?因此,每次加载页面时,订单都会有所不同。
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/
jsfiddle http://jsfiddle.net/guest271314/d4p39/
这篇关于随机化我追加到另一个的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文