HTML onwheel attribute

HTML onwheel attribute: This attribute defines the wheel of a pointing device is rolled up or down over an element. The onwheel attribute also defines the user scrolls on an element by using a mouse. And it is a section of the Event Attributes.

HTML onwheel attribute

This attribute will not be supported in HTML 4. And it was newly added to HTML 5.

Attribute Value: This attribute contains a single value script and it works when onwheel attribute called. It is supported by all HTML elements.

Syntax: <element onwheel =”script”>

Browser Support

This attribute was supported by different types of browsers. They are as follows:

  • Chrome -31.0
  • Firefox – 17.0
  • InternetExplorer – Not supported
  • Safari – Not supported
  • Opera -18.0

Example:

<!DOCTYPE html>
<html>
<head>
<style>
#myDIV {
  border: 1px solid black;
}
</style>
</head>
<body>

<div id="myDIV" onwheel="myFunction()">This example demonstrates how to assign an "onwheel" event event to a DIV element. Roll the mouse wheel over me - either up or down!</div>
<p>A function is triggered when you roll the mouse wheel over div. The function sets the font-size of div to 35 pixels.</p>
<p><strong>Note:</strong> The onwheel event is not supported in Internet Explorer or Safari.</p>
<script>
function myFunction() {
  document.getElementById("myDIV").style.fontSize = "35px";
}
</script>

</body>
</html>

Output:

HTML onwheel attribute