I have written a small jQuery script that checks the computed size of a div, sets the css height of this div to that height, then uses this height to calculate whether to initiate an animation or not.
The have printed out the variables to check that they are the same and it seems they are but it never seems to run through the ‘if’ even when they are the same. Can anyone see what I am doing wrong here?
The main aim of this code is to hide an absolutely-positioned div off of the screen, then when an anchor is clicked the script is run and the div will slide in or out accordingly.
Thanks in advance!
$(document).ready(function(){
var outerdivheight = $('.login_wrap').outerHeight();
divheight = 0 - outerdivheight;
$('.login_wrap').css("top", divheight + "px");
$('#login_tab').click(function(){
if (parseInt($('.login_wrap').css('top') == outerdivheight)) { marg = '0'; } else { marg = divheight; }
$('.login_wrap').stop().animate({'top':marg}, 'slow');
});
});
You have some parentheses in the wrong place:
Try
(parseInt($('.login_wrap').css('top')) == outerdivheight)