JavaScript 中 screenY 滑鼠事件的作用是什麼?


當事件觸發時,screenY 滑鼠事件將返回滑鼠指標的縱座標。

示例

可以嘗試執行以下程式碼學習如何在 JavaScript 中實現 screenY 滑鼠事件。

<!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.screenX;
            var y_coord = event.screenY;
            var xycoords = "X coords= " + x_coord + ", Y coords= " + y_coord;
            document.write(xycoords);
         }
      </script>
   </body>
</html>

更新時間:2020-5-23

70 次瀏覽

開啟你的職業生涯

修完課程獲得認證

馬上開始
廣告