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

How to check if Y coordinates of mouse is greater than a value

本文关键字:大于 是否 一个 坐标 何检查 检查 鼠标      更新时间:2023-09-26

我可以通过这个检查鼠标的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);
  };
});

这是你想要的吗?