Clickheretogetthex(hor"/> Clickheretogetthex(hor">

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

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

王林
王林轉載
2023-09-24 14:05:021115瀏覽

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

當滑鼠事件被觸發時,pageY滑鼠事件屬性用於取得滑鼠指標的垂直座標。座標是相對於螢幕的。

範例

您可以嘗試執行以下程式碼來了解如何實作pageYJavaScript 中的滑鼠事件。

<!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>

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

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