JavaScript 中 clientY Mouse Event 的作用是什麼?


觸發滑鼠事件時,clientY 滑鼠事件屬性用於獲取滑鼠指標的縱座標。此座標根據當前視窗而定。

示例

可嘗試執行以下程式碼,瞭解如何在 JavaScript 中實現 clientY 滑鼠事件。

<!DOCTYPE html>
<html>
   <body>
      <p onclick = "coordsFunc(event)">Click here to get the x (horizontal) and y (vertical) coordinates (according to current window) of the mouse pointer.</p>
     
      <script>
         function coordsFunc(event) {
            var x_coord = event.clientX;
            var y_coord = event.clientY;
            var xycoords = "X coords= " + x_coord + ", Y coords = " + y_coord;
            document.write(xycoords);
         }
      </script>
   </body>
</html>

更新於: 23-5-2020

115 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告