How to stop .hover from triggering inside an if statement?

天涯浪子 提交于 2019-12-13 04:35:07

问题


I am trying to stop a .hover action whenever a div changes height.

This is the code I have so far:

if (secondary.height() <= 300) {
    secondary.css("height",300);
    secondary.hover(function(){
        jQuery('.comments-holder').css("height",mediumHeight);
    },
    function(){             
        jQuery('.comments-holder').css("height",minHeight);     
    });
} else {
    // DO SOMETHING ELSE
}

The problem I am having is that .hover is being triggered no matter what the if statement implies.


回答1:


Check for the height inside the hover function.

secondary.hover(function(){
    if (secondary.height() <= 300) {
      jQuery('.comments-holder').css("height",mediumHeight);
      }
},
function(){    
    if (secondary.height() <= 300) {         
     jQuery('.comments-holder').css("height",minHeight);    
    } 
});


来源:https://stackoverflow.com/questions/19014739/how-to-stop-hover-from-triggering-inside-an-if-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!