我需要做的是:原始状态:
<div class="shuffledv">
<div id="1"></div>
<div id="2"></div>
<div id="3"></div>
</div>
<div class="shuffledv">
<div id="4"></div>
<div id="5"></div>
<div id="6"></div>
</div>
洗牌后:
<div class="shuffledv">
<div id="2"></div>
<div id="3"></div>
<div id="1"></div>
</div>
<div class="shuffledv">
<div id="5"></div>
<div id="4"></div>
<div id="6"></div>
</div>
第一个 div 中的 div 保留在那里但被洗牌,同样的情况发生在具有相同类的第二个 div 上。要在特定 div 中随机播放 div,我使用如下内容:
function shuffle(e) { // pass divs inside #parent to the function
var replace = $('<div>');
var size = e.size();
while (size >= 1) {
var rand = Math.floor(Math.random() * size);
var temp = e.get(rand); // grab a random div from #parent
replace.append(temp); // add the selected div to new container
e = e.not(temp); // remove our selected div from #parent
size--;
}
$('#parent').html(replace.html()); // add shuffled divs to #parent
}
所谓的谎言:shuffle('#parent .divclass')
所有有类的 Divdivclass
都在里面,#parent
我认为它应该开始像
function shuffle() {
$(".shuffledv").each(function() {
然后执行某种形式的原始功能,但此时我完全迷失了方向。我不知道如何从这里继续前进。如果您需要更多信息,请告诉我。