当鼠标滚动在 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.