views:

19

answers:

2

Hello I'm working to slide a DIV to the left (off the page). ...

I have the following which works:

$('.mybigbox').live('click', function() {
 leftDistance = $(this).attr('name'); // set px so I know how far
 $lefty.animate({left:leftDistance}) // Makes the slide
});

What what I want to happen, is on the first click it animates with the above, but on the next click it returns to default. (kind of like a toggle, on off button.

Ideas? thank you

A: 

Something like

var defaultLeftPosition = null;

$("#yourdiv").toggle(function(){
    if (defaultPosition != null)
        defaultLeftPosition = $(this).offset().left;
    // do your code for animating to the new position
},
function(){
    // get default position from variable defaultLeftPosition and set left 
    // to that inside animate
});
rahul
A: 

See Demo Here


If I understand you correctly, try this:

$('.mybigbox').live('click', function() {
   $lefty.animate({width:'toggle');
});
Sarfraz