PDA

View Full Version : && operator



noob_developer
05-28-2008, 03:41 PM
I have this script which slides down to cover a picture and then back up once the picture has been loaded. There are two variables that I am working with - the height of the div that is being slid up and down and the direction (1 or -1). My issue is that when the div has completed sliding back up I need it to call the clearInterval function. This is my code:

if((cont.offsetHeight < 0) && (direction == -1)){ /* meaning slide down */
clearInterval(cont.timer);
}

The problem that I am facing is that if I just have the cont.offsetHeight < 0 the block of code excutes at the appropriate time - the same for the direction == -1. However, when I have the code the way it is laid out above the condition fails to execute even though it should. Is there another And condition or is there something else that I am missing? I am somewhat new at coding javaScript so I appologize if the solution is odvious and I am just not seing it. Thanks,

-S

noob_developer
05-28-2008, 03:57 PM
I got it. Apperently the direction variable and the offsettheight were never -1 and 0 at the same time. I had to check and see when the offsetHeight was less than 1 then it worked. It had nothing to do with the && operator.

-S