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 Swedberg
www.englishrules.com
www.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;
}
});