Jquery如果鼠标离开或鼠标进入状态 [英] Jquery if condition on mouse leave or mouse enter

查看:101
本文介绍了Jquery如果鼠标离开或鼠标进入状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello People这里是我的jquery代码。

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....

类似......

$(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?

推荐答案

你应该玩一个根据更新的变量 mouseenter mouseleave 有关 val3 和<$ c的信息$ c> val4

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;
    }
});

并测试它

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

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

这篇关于Jquery如果鼠标离开或鼠标进入状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆