[whatwg] Suggestion: Mouse Wheel events for Web Apps 1.0

Chris Griego wrote:
> Currently the only way to capture and use the mouse wheel on the web
> is within the Macromedia Flash v7 plugin which added event handling
> for the mouse wheel.

That's incorrect. Both IE (since 5.5?) and Mozilla supports this. 
Unfortunately they do it in different ways.

IE:

element.attachEvent("onmousewheel", function () {
    document.title = window.event.wheelDelta;
});

Mozilla:

element.addEventListener("DOMMouseScroll", function (e) {
    document.title = e.detail;
}, true);

The values here are bit different.

In Mozilla, if you have set Mozilla to scroll a certain number of rows 
you get the number of steps here. If you have it set to scroll one page 
at a time you get large values and I'm not sure if these represents the 
number of rows in some way.

In IE it returns multiples of 120 but I guess it really represent 3 rows 
* 40 twips/row and that changing this in some control panel applet or in 
the registry might give you other alternative results.

The values in IE is negative when Mozilla is positive and the other way 
around.

Here is a pretty simple way to unify these to some extent:

function getWheelDelta(e) {
    if (window.event) { // IE
       return e.wheelDelta / 40;
    } else {
       // In case the user has "one screen at a time" we get a
       // very big value
       var v = e.detail || 0;
       if (v > 1000) {
          v = 3;
       } else if (v < -1000) {
          v = -3;
       }
       return - v;
    }
}

erik

Received on Monday, 20 June 2005 15:01:21 UTC