July 18, 2001 - Measuring Mousewheel Rotations (IE6) | WebReference

July 18, 2001 - Measuring Mousewheel Rotations (IE6)

Yehuda Shiran July 18, 2001
Measuring Mousewheel Rotations (IE6)
Tips: July 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Internet Explorer 6 supports a new event, onmousewheel. The onmousewheel event is triggered when the user rotates the wheel button. The event object can be queried to find all the event's properties. Only the onmousewheel event exposes the wheelDelta property. The wheelDelta property indicates the direction and the length of the wheel rotation. The length is given in a multiple of 120. A negative wheelDelta indicates the wheel has been rotated towards the user. A positive value indicates it was rotated away from the user. Put your mouse on the image below and rotate the wheel button. The image should change its position on the page:

Here is the source code:

var verticalDistance = 1;
function shiftUpDown() {
  objImage.style.position = "relative";
  verticalDistance = countRotations(verticalDistance);
  objImage.style.top = verticalDistance * 10;
  return false;
function countRotations(addRotations) {
  addRotations += event.wheelDelta/120;   
  return addRotations; 
// -->
<IMG ID="objImage" SRC="football.jpg" onmousewheel="shiftUpDown()" WIDTH="400"