What I need done is: Original State:
<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')
所有带有类名为divclass
的Div都在#parent
内部。
我认为它应该像这样开始:
function shuffle() {
$(".shuffledv").each(function() {
然后执行某种原始功能,但在这一点上我已经完全迷失了。我不知道如何从这里继续。如果需要更多信息,请告诉我。