&nbs"/>    &nbs">

首頁  >  文章  >  web前端  >  當滑鼠滾輪在HTML元素上向上或向下滾動時執行腳本?

當滑鼠滾輪在HTML元素上向上或向下滾動時執行腳本?

王林
王林轉載
2023-09-23 10:49:021303瀏覽

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

以上是當滑鼠滾輪在HTML元素上向上或向下滾動時執行腳本?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除