Javascript DOM onwheel Event via HTML Tag onwheel function

Introduction

In JavaScript:

object.onwheel = function(){
       myScript};

This example uses the HTML DOM to assign an "onwheel" event to a DIV element.

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

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

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {/*from  w  w w . jav  a2  s.c  om*/
  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").onwheel = function() {myFunction()};

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

</body>
</html>
Bubbles: Yes
Cancelable: Yes
Event type: WheelEvent
Supported HTML tags: All HTML elements



PreviousNext

Related