Have you looked at JQ's built in toggle event?
You won't have to keep track of even/odd clicks at all if you use
that...


On Mar 8, 8:53 am, Karl Swedberg <[EMAIL PROTECTED]> wrote:
> Not sure if this is neater, but it does have fewer lines of code:
>
> var stoggle = false;
> $("#button").click(function(){
>         var extra = 150, divTop = parseInt($('#div').css('top'));
>         $('#div').animate({top: !stoggle ? divTop + extra : divTop - extra},
> 400);
>         stoggle = !stoggle;
>
> });
>
> --Karl
> _________________
> Karl Swedbergwww.englishrules.comwww.learningjquery.com
>
> On Mar 7, 2008, at 7:26 PM, jquertil wrote:
>
>
>
> > I have this code shown below - it works fine but I imagine there is a
> > neater way to accomplish this... anyone?
>
> > I would love to somehow shrink this to less lines of code.
>
> > stoggle = 0;
> > $("#button").).click(function(){
> >    var extra = 150;
> >    if(stoggle==0){
> >            
> > $('#div').animate({top:parseInt($('#div').css('top'))+extra},400);
> >            stoggle = 1;
> >    }else{
> >            
> > $('#div').animate({top:parseInt($('#div').css('top'))-extra},400);
> >            stoggle = 0;
> >    }
> > });

Reply via email to