Javascript DOM onwheel Event

Introduction

When the user rolls the mouse wheel over a <div> element, change its font-size:

A function is triggered when you roll the mouse wheel over div.

The function sets the font-size of div to 35 pixels.

This example uses the addEventListener() method to attach a "wheel" event to a DIV element.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {/*  w ww.  j  a va2 s. c  o m*/
  border: 1px solid black;
}
</style>
</head>
<body>

<div id="myDIV">
Roll the mouse wheel over me - either up or down!</div>
<script>
document.getElementById("myDIV").addEventListener("wheel", myFunction);

function myFunction() {
  this.style.fontSize = "35px";
}
</script>

</body>
</html>

The onwheel event occurs when the mouse wheel is rolled up or down over an element.

Bubbles: Yes
Cancelable: Yes
Event type: WheelEvent
Supported HTML tags: All HTML elements



PreviousNext

Related