Mouse Wheel Events

17 views
Skip to first unread message

karlzilles

unread,
Sep 20, 2009, 7:57:59 PM9/20/09
to SVG Web
Hi,

I'm looking to do zooming ala google maps with the mouse wheel.

When I do something along the lines of:

circle.addEventListener('DOMMouseScroll', function(evt) {
alert("wheel");
}, false);

It works in the native SVG mode of firefox, but not using the flash
renderer.

Is there some way I can catch mouse scroll events? Or is it something
you can add easily ;)

Thanks,

Karl

Bradley Neuberg

unread,
Sep 20, 2009, 8:02:35 PM9/20/09
to svg...@googlegroups.com
Here's a snippet I've seen Michael Neutze use:

// Mousewheel Scrolling thanks to
// http://blog.paranoidferret.com/index.php/2007/10/31/javascript-tutorial-the-scroll-wheel/

function hookEvent(element, eventName, callback)
{
if(typeof(element) == "string")
element = document.getElementById(element);
if(element == null)
return;
if(element.addEventListener)
{
if(eventName == 'mousewheel')
{
element.addEventListener('DOMMouseScroll',
callback, false);
}
element.addEventListener(eventName, callback, false);
}
else if(element.attachEvent)
element.attachEvent("on" + eventName, callback);
}

Bradley Neuberg

unread,
Sep 20, 2009, 8:03:29 PM9/20/09
to svg...@googlegroups.com
BTW, what you are doing won't work; scroll wheel events don't get fired on the circle element. You should probably hook it to a DIV or container element in which your SVG is located.
Reply all
Reply to author
Forward
0 new messages