首頁  >  文章  >  web前端  >  在JavaScript中,clientY滑鼠事件的作用是什麼?

在JavaScript中,clientY滑鼠事件的作用是什麼?

WBOY
WBOY轉載
2023-08-19 22:33:25622瀏覽

在JavaScript中,clientY滑鼠事件的作用是什麼?

當滑鼠事件被觸發時,使用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>

以上是在JavaScript中,clientY滑鼠事件的作用是什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除