Jquery if condition on mouse leave or mouse enter

故事扮演 提交于 2019-12-31 02:50:06

问题


Hello People here is my jquery code.

$(val1+","+val2).mouseleave(function(){

    $('.opacity').remove();
    $(val3).show();
    $(val4).hide();

});

i want to edit this code in such a way that after

$(val1+","+val2).mouseleave(function(){
    if mouse doe not  enter val3 or val4
then 
    $('.opacity').remove();
$(val3).show();
$(val4).hide();
else
    nothing....

something like ...

$(val1 + "," + val2).mouseleave(function() {

    if ($(val3 + "," + val4).mouseenter) {
    } else {
        $('.opacity').remove();
        $(val3).show();
        $(val4).hide();
    }

});

obviously above does not work ... iam wrong somewhere near if condition how to fix this?


回答1:


You should play with a variable updated according to the mouseenter and mouseleave information about val3 and val4

var isHoverSpecialDiv = false;

$(val3 + "," + val4).hover(
    function(){
        isHoverSpecialDiv = true;
    },
    function(){
        isHoverSpecialDiv = false;
    }
});

And test it

$(val1 + "," + val2).mouseleave(function() {

    //Test condition
    if (isHoverSpecialDiv == false) 
    {
        $('.opacity').remove();
        $(val3).show();
        $(val4).hide();
    }
});


来源:https://stackoverflow.com/questions/17378599/jquery-if-condition-on-mouse-leave-or-mouse-enter

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