More on the mouse wheel

Daniel left a comment on my post about mouse wheel support saying he'd managed to get it working in managed code so I decided to take another look. It turns out that the object to which you attach your handler is critical and differs between IE and Firefox:

    new EventHandler<HtmlEventArgs>(this.MouseScrollWheel)); // IE
    new EventHandler<HtmlEventArgs>(this.MouseScrollWheel)); //FF

So you need to attach to the onmousewheel event on the Document object for IE and the DOMMouseScroll event on the Window object for FireFox (I haven't tried Safari I'm afraid). That said, this didn't get me very much further as I can't recover the scroll wheel data for Firefox. My MouseScrollWheel handler looks like this:

private void MouseScrollWheel(object sender, HtmlEventArgs e)
    ScriptObject eventobject = e.EventObject;

    double wheelAmount =
        eventobject.GetProperty("detail") != null ?
        (double)eventobject.GetProperty("detail") * -1.0 :
        (double)eventobject.GetProperty("wheelDelta") / 40.0;

    if (wheelAmount > 0)


as IE uses the events wheelDelta property and Firefox uses the detail property (there is also a difference in scaling between the two hence the twiddle factors). There's a good tutorial on the scroll wheel here. The trouble is, the detail property is always 0.0 for me so this solution works in IE but not in Firefox (well it works in Firefox but the image zooms out irrespective of which way you turn the scroll wheel!). Ideas anyone?

Technorati Tags: ,,
Comments (4)
  1. Derek Lakin says:

    Hi Mike,

    Further to my earlier email, it seems that Joe’s post doesn’t have the DeepZoom stuff, in it, but MIke’s does:

    As I recall, the scroll helper in Mike’s demo zoomz on the mouse position instead of the top left like yours does :).

  2. MikeO [MSFT] says:

    Hi Derek. Thanks – I did see Mike’s post but it was taking an age to download so I gave up :-). Will try again some other time. I didn’t want to zoom on the mouse position – I wanted to zoom on the current centrepoint but that’s not quite working as you point out. There’s something wrong with my viewport origin calculations. I’ll look at it again when I have a chance… Mike

  3. Misc Funny Little Logic Errors More on the mouse wheel Powershell 2008 Scripting Games – My solutions

  4. Jeff Paries with OOJS part 2, Chrishayuk with a fix to a listbox stretch problem, Karen Corby gives up

Comments are closed.

Skip to main content