Javascript 如何检查鼠标的Y坐标是否大于某个值

Javascript 如何检查鼠标的Y坐标是否大于某个值,javascript,mouseevent,mouse,coordinates,Javascript,Mouseevent,Mouse,Coordinates,我可以通过这个检查鼠标的Y坐标 $(document).mousemove(function(e) { var MouseY = "( " + event.clientY + " )"; }); 但是当一个函数大于一个值,比如说20px时,如何触发它。我想这个不行 if (MouseY > 20){ alert('yes'); } 为什么不合并这两个片段 $(document).mousemove(function() { var threshold = 20; if

我可以通过这个检查鼠标的Y坐标

$(document).mousemove(function(e) {
  var MouseY = "( " + event.clientY + " )";
}); 
但是当一个函数大于一个值,比如说20px时,如何触发它。我想这个不行

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

为什么不合并这两个片段

$(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);
  };
});
这是你想要的吗