2014-09-13 82 views
0

我可以通过它检查鼠标的Y坐标。如何检查鼠标的Y坐标是否大于一个值

$(document).mousemove(function(e) { 
    var MouseY = "(" + event.clientY + ")"; 
}); 

但如何触发一个函数,当它大于一个值,比如20px。我想这一个不工作

if (MouseY > 20){ 
    alert('yes'); 
} 

回答

1

为什么不把你的两个片段结合起来?

$(document).mousemove(function() { 
    var threshold = 20; 
    if(event.clientY > threshold) { 
    alert('Current mouse position is: ' + event.clientY); 
    // or call another function here like: 
    // react(event.clientY); 
    }; 
}); 

这是你想要的吗?

相关问题