触发鼠标事件后,将使用pageY鼠标事件属性获取鼠标指针的垂直坐标。坐标是相对于屏幕的。
您可以尝试运行以下代码,以了解如何在JavaScript中实现pageY Mouse事件。
<!DOCTYPE html>
<html>
   <body>
      <p onclick="coordsFunc(event)">Click here to get the x (horizontal) and y (vertical) coordinates of the mouse pointer.</p>
      <script>
         function coordsFunc(event) {
            var x_coord = event.pageX;
            var y_coord = event.pageY;
            var xycoords = "X coords= " + x_coord + ", Y coords= " + y_coord;
           
            document.write(xycoords);
         }
      </script>
   </body>
</html>