Execute a script when the mouse wheel rolls up or down over an element in HTML?


The onwheel attribute triggers when the mouse wheel rolls up or down over an element. You can try to run the following code to implement onwheel attribute −

Example

<!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>

Updated on: 03-Mar-2020

76 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements