當滑鼠滾輪在 HTML 中某元素上向上或向下滾動時執行指令碼?


onwheel 屬性會在滑鼠滾輪在元素上向上或向下滾動時觸發。你可以嘗試執行以下程式碼來實現onwheel 屬性−

示例

<!DOCTYPE html>
<html>
   <body>
      <h3 id = "myid" onwheel = "mouseWheel()">
         This is demo heading.
      </h3>
      <p>Click above and use mouse wheel to change the heading color.</p>
      <script>
         function mouseWheel() {
            document.getElementById("myid").style.color = "red";
         }
      </script>
   </body>
</html>

更新於: 03-3-2020

92 次瀏覽

開啟你的職業

完成課程獲得認證

入門
廣告
© . All rights reserved.