问题
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