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


當觸發了滑鼠事件時,pageY 滑鼠事件屬性用於獲取滑鼠指標的縱座標。此座標與螢幕相關。

例項

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

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

更新於: 2020 年 5 月 23 日

93 次瀏覽

啟動你的 職業

透過完成該課程獲得認證

開始
廣告