开发者

How to use javascript OR operator?

I've been breaking my head over this 'simple' javascript snippet:

$("#hitbox").mouseleave(function() {
  if($("#sub-wrapper-1").height() &l开发者_JAVA技巧t; 179 || $("#sub-wrapper-2").height() < 179 ) {     
    $("#hitbox").animate({ "height" : '0px' }, 800), 
  } else {
    $("#hitbox").stop();
  }
});

Could you guys nudge me in the right direction on how to use the OR operator in javascript? The above code doesn't throw any errors, but it seems as it runs the function as an AND operator.


Your OR operator is right (in fact in your case is simple javascript!)

It seems you have an error here

$("#hitbox").animate({ "height" : '0px' },800),

fix it as

$("#hitbox").animate({ height : '0px' },800);


I find sometimes JS operators (in this case your || or) don't compare whole clauses, only the next item starting the clause. you may want to try wrapping your clauses w/ parens like so:

if(($("#sub-wrapper-1").height() < 179) || ($("#sub-wrapper-2").height() < 179 ))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜