tags:

views:

38

answers:

2

I'm trying to integrate an animation by using the bezier path plug-in and I can't seem to implement it right.

Stripped down, here's what I have:

    $('#next2btn').live('click', function(){
       $(this).attr('id','next3btn');
        $('#content2').show(300, function() {
            $('#account').fadeTo(500,1.0)
            var arc_params = {
                center: [278,120],
                radius: 186,
                start: -90,
                end: 90,
                dir: -1
                };
            });
        $("#account").animate({path : new $.path.arc(arc_params)},1000);
});

So, I'm trying to add this piece of code into what I have:

    var arc_params = {
                center: [278,120],
                radius: 186,
                start: -90,
                end: 90,
                dir: -1
              };
        });
$("#account").animate({path : new $.path.arc(arc_params)},1000)

which works on its own as does the other.

I'm thinking it's something about declaring that variable and where I do that.

I'm essentially chaining a few different animations/actions upon a button click.

Thanks for any insight- kj

A: 

That snippet you posted won't work by itself; it's syntactically incorrect (mismatching )).

You'll most probably be wanting:

$('#next2btn').live('click', function(){
    $(this).attr('id','next3btn');

    $('#content2').show(300, function() {
        $('#account').fadeTo(500,1.0);

        var arc_params = {
                center: [278,120],
                radius: 186,
                start: -90,
                end: 90,
                dir: -1
            };

        $("#account").animate({
            path : new $.path.arc(arc_params)
        }, 1000);
    });
});

(which of course, is equivilent to:)

$('#next2btn').live('click', function(){
    $(this).attr('id','next3btn');

    $('#content2').show(300, function() {
        $('#account').fadeTo(500,1.0);

        $("#account").animate({
            path : new $.path.arc({
                center: [278,120],
                radius: 186,
                start: -90,
                end: 90,
                dir: -1
            })
        }, 1000);
    }); 
});
Matt
They're equivalent with regards to `arc_params` being sent inline in the second example, but `$('#account').animate()` will fire on different times in the two examples. Guess it's just a typo :)
Simen Echholt
@Simen: Whoops... indeed. Thanks.
Matt
+1  A: 

You're right in your assumptions. As you are declaring arc_params inside the callback function of show, it is only visible inside the function, and not outside of it, it in the following code. Declare it outside the function, so it will be visible to your animate function.

Here's a simple example of how it works, independent of any other code:

var a = "outside function";
function someFunction() {
    var b = "inside function";
}

alert(a); //alerts correctly
alert(b); //gives error: 'b is not defined' (as it is not visible from outside the function
Simen Echholt
Ok, this is making sense. However, I'm thiking in terms of theory now.. using a callback function is the only way I've been able to pause an action. Using delay(xxxx) has never worked but now I think I need to investigate the animation que more and see where/why I started using a callback function to be able to chain stuff. I think it's all the parenthesis and brackets when inserting into an existing function.... actionscript was easier for me for some reason! Thanks
kelly