2013-12-07 26 views
-1

我在Edge Animate中工作。隨機數和位置 - 我缺少一個數字

我想在兩個不同的地方放置符號,當我生成它們時,我總是缺少一個符號。

此外,我希望能夠將前3個數字放在自己的容器中 - 如果數字是2,它應該在location1[1]中,如果數字是8,則應放置在location1[7]中。我不知道我該如何做到這一點。

numbers數組包含數字1,2,3,4,5,6,7,8,9,10的符號名稱。 location1是一個數組,其中包含每個可能的3個數字的容器名稱。

其餘的容器將成爲可丟棄物。

location2是一個數組,其中包含剩餘數字的容器名稱,該數字將成爲可拖動的。

這裏是我的代碼:

var numbers = ['num1','num2','num3','num4','num5','num6','num7','num8','num9','num10']; 
var location1 = ['c1','c2','c3','c4','c5','c6','c7','c8','c9','c10'];  
var location2 = ['circle0','circle1','circle2','circle3','circle4','circle5','circle6','circle7','circle8','circle9']; 


//randomize numbers 
var placedNumbers = numbers.sort(function() {return 0.5 - Math.random()}); 

// place the 3 first numbers on the top list. 
for (i=0;i<3;i++){ 
sym.createChildSymbol(placedNumbers[i],location1[i]); 
} 
// place the rest of the numbers in the bottom list 
for (j=3;j<11;j++){ 

sym.createChildSymbol(placedNumbers[j],location2[j]); 

} 

回答

0

我不熟悉的動畫包,但是這可能意味着你在正確的方向。小提琴here使用div作爲容器(從for循環生成每個div id)。這是主要位:

for (i=0;i<3;i++){ 
    $('#divOne').append('<div id = ' + location1[i] + '>' + placedNumbers[i] + '</div>'); 
} 
// place the rest of the numbers in the bottom list 
for (i=3;i<10;i++){ 
    $('#divTwo').append('<div id = ' + location2[i] + '>' + placedNumbers[i] + '</div>'); 
} 
+0

謝謝你的回答。然而,這並不完全正確,因爲第一個列表中的數字需要到達他們的位置。 – Edgedudette

+0

謝謝你的回答。這是更好,但仍不完全正確。在第一個列表中,我希望將數字放在它們各自的div中 - 有10個div來放置數字1到10 - 因此放置在開頭的3個數字需要放在正確的位置 - 例如數字2將在位置1 [2]的div 3中。這有意義嗎?但是,由於學生將嘗試按順序填寫數字,因此底部數字必須是隨機的。 – Edgedudette

+0

我不明白爲什麼,但我仍然沒有得到10個數字 - 太奇怪了! – Edgedudette