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

HTMLWeb DevelopmentFront End Technology

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>
raja
Published on 14-Mar-2018 07:15:20
Advertisements