Welcome to MSDN Blogs Sign in | Join | Help

Mike Ormond's Blog

In my world, things would be simpler than this...

News

  • Add to Technorati Favorites

    These postings are provided "AS IS" with no warranties, and confer no rights. The use of any script / code samples is subject to the terms specified here.

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:

HtmlPage.Document.AttachEvent("onmousewheel", 
    new EventHandler<HtmlEventArgs>(this.MouseScrollWheel)); // IE
HtmlPage.Window.AttachEvent("DOMMouseScroll", 
    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)
        Zoom(1.1);
    else
        Zoom(0.9);

    e.PreventDefault();
}

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: ,,
Posted: Monday, March 10, 2008 7:59 AM by MikeOrmond
Filed under:

Comments

Derek Lakin said:

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: http://blogs.msdn.com/mharsh/archive/2008/03/05/slides-and-demos-from-my-mix-08-talk.aspx

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

# March 10, 2008 6:50 AM

MikeOrmond said:

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

# March 10, 2008 10:08 AM

Trumpi's blog said:

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

# March 10, 2008 3:34 PM

Community Blogs said:

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

# March 15, 2008 2:09 AM
New Comments to this post are disabled
Page view tracker