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();

here is my code ı try to delete numbers and use until finish array and i want to do it 1 by 1

3
  • Replace the for loop with while(items.length > 0), or your loop will stop before the array is empty. Remove the [] from a = [Math... - You're creating an array with one element and passing that array to scale(). Commented Jun 4, 2013 at 11:47
  • 1
    Possible duplicate stackoverflow.com/questions/14006480/… Commented Jun 4, 2013 at 11:50
  • P.S. delay() only applies a delay to the animation queue on the individual element, so all of your elements will be processed at once. Commented Jun 4, 2013 at 11:53

2 Answers 2

0

You'll need the index of the number in the array for splice(), not the string itself:

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

It would probably be easier to just shuffle the array and pop of the last value to get a random array index, and at the same time removing it from the array:

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();

not sure where the .transition() method comes from, but guessing it has a callback ?

FIDDLE

Sign up to request clarification or add additional context in comments.

3 Comments

thank you very much its work so fine and transition is ricostacruz.com/jquery.transit transform jquery easyly for every browser thnx work fine like what ı want
everytime it gives same order i want to diffirent orders everytime :(
@UğurOruc - My bad, seems I messed up the random function, fixed it now.
0

You need to

items.splice($.inArray(number, items),1);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.