當滑鼠滾輪滑過 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>

更新日期:30-May-2020

288 次瀏覽

開啟您的 職業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.