Internal loop only runs once, containing loop runs endlessly

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2012-09-18T09:36:32Z Indexed on 2012/09/18 9:37 UTC
Read the original article Hit count: 239

Filed under:
|

noob question I'm afraid.

I have a loop that runs and rotates the hand of a clock and an internal loop that checks the angle of the hand if it is 90, 180, 270 and 360. On these 4 angles the corresponding div is displayed and its siblings removed. The hand loops and loops eternally, which is what I want, but the angle check only runs the loop once through the whole 360. As the hand passes through the angles it is correctly displaying and removing divs but is doesn't continue after the first revolution of the clock.

I've obviously messed up somewhere and there is bound to be a more efficient way of doing all this. I am using jQueryRotate.js for my rotations. Thanks for your time.

jQuery(document).ready(function(){
var angle = 0;
setInterval(function(){
     jQuery("#hand").rotate(angle);
     function movehand(){
      if (angle == 90) {
      jQuery("#intervention").fadeIn().css("display","block").siblings().css("display","none");
    } else if (angle == 180) {
      jQuery("#management").fadeIn().css("display","block").siblings().css("display","none");
    } else if (angle == 270) {
      jQuery("#prevention").fadeIn().css("display","block").siblings().css("display","none");
    } else if (angle == 360) {
      jQuery("#reaction").fadeIn().css("display","block").siblings().css("display","none");
    } else {movehand;}
};
      movehand();
      angle+=1;
},10);
});

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery