Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript function variables issue

Tags:

jquery

What is the problem with my script? When I execute it, the alert (line 2) gives me "100,200,300undefinedundefined", so is seems like 100,200,300 is interpreted as h1 when I would like it to be h1, h2 and h3 (with the commas).

function myanimation(h1,h2,h3) {

        alert(h1 + h2 + h3);
        $("#h1").animate({"left": h1});
        $("#h2").animate({"left": h2});
    }

    var moves = new Array()
    moves[1] = [100,200,300];
    moves[2] = [300,200,100];
    moves[3] = [-500,-300,0];

    var i = 1;

    function animatenow(){
        myanimation(moves[i]);
        i++;
    }

$('#launch').click(function() {
        setInterval(animatenow, 5000);
    });
like image 572
Adam Strudwick Avatar asked Jun 27 '26 00:06

Adam Strudwick


1 Answers

You are passing an array into myanimation, which corresponds to your h1 parameter. You aren't passing h2 or h3, so those are undefined.

like image 135
rosscj2533 Avatar answered Jun 29 '26 17:06

rosscj2533