Question

I would like to take the mousewheel event on an element, but have't found anything on the documentation. Do you have an example of the kind?

Was it helpful?

Solution

I'm not sure of any direct Snap methods to use mousewheel, but I guess you can just add a mousewheel listener...this example works in Chrome, you may need to tweak and add test case for different browsers.

var s = Snap(400, 620);
var c = s.circle(30,30,30);

if( (/Firefox/i.test(navigator.userAgent)) ) {
    s.node.addEventListener("DOMMouseScroll", mouseWheelHandler, false);
} else {
    s.node.addEventListener("mousewheel", mouseWheelHandler, false);
}

function mouseWheelHandler (ev) { 
    ev.preventDefault();
    console.log( ev.target.localName );
}

Edit: Have updated to check for firefox as well.

jsfiddle example

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top