0
var items = ["1","2","3","4","5","6","7","8","9","10","11","12"];
function bigger(){
    for(var i=0;i<items.length;i++){
        a = [Math.floor(Math.random() * items.length)+1];
        scale(a);   
    }   
}
function scale(number){
    $("#inner"+number+"").delay(100).transition({scale:1},300);
    items.splice(number,1);
} 
bigger();

这是我的代码,我尝试删除数字并使用直到完成数组,我想逐个执行

4

2 回答 2

0

您需要数组中数字的索引 for splice(),而不是字符串本身:

items.splice( items.indexOf(number), 1 );

只打乱数组并弹出最后一个值以获得随机数组索引可能会更容易,同时将其从数组中删除:

var items = ["1","2","3","4","5","6","7","8","9","10","11","12"];

function scale(){
    var number = items.sort(function() { return 0.5 - Math.random();}).pop();
    $("#inner"+number+"").delay(100).animate({opacity:1},300, function() {
        scale();
    });
} 

scale();

不确定该.transition()方法来自哪里,但猜测它有一个回调?

小提琴

于 2013-06-04T11:46:54.577 回答
0

你需要

items.splice($.inArray(number, items),1);
于 2013-06-04T11:47:44.920 回答