當滑鼠滾動在 HTML 中的元素上時,執行指令碼?


當滑鼠在元素上滾動時,onwheel 屬性會觸發。

示例

你可以嘗試執行下面的程式碼,在 HTML 中滑鼠滾動在元素上時執行指令碼 −

<!DOCTYPE html>
<html>
   <head>
   </head>
   <body>
      <div id = "myDIV" onwheel = "display()">This is demo text. Roll the mouse wheel here.</div>

      <script>
         function display() {
            alert("Mouse Wheel used!");
         }
      </script>

   </body>
</html>

更新於: 2020 年 5 月 30 日

288 次瀏覽

開啟你的 職業生涯

完成課程後獲得證書

開始
廣告
© . All rights reserved.