I'm trying to make a stage that can be zoomed by mousewheel. I'm using the stage.scale and jquery event. But I have not been able to make the zoom done with the mouse pointer as center. So when my mouse is on a point, I want to zoom in it centrically.
I've make this example, that doesen't work for now : http://fiddle.jshell.net/rr7pLapz/1/
Here is my zoom function :
$("#cont").bind('mousewheel', function(e) {
var x = e.offsetX;
var y = e.offsetY;
if (e.originalEvent.wheelDelta > 0) {
STAGE.scale({
x:STAGE.scale().x+1,
y:STAGE.scale().y+1
});
STAGE.x(-x + 500/(STAGE.scale().x));
STAGE.y(-y + 350/(STAGE.scale().y));
STAGE.batchDraw();
}
else {
if (STAGE.scale().x > 1) {
STAGE.x(-x + 500/(STAGE.scale().x));
STAGE.y(-y + 350/(STAGE.scale().y));
STAGE.scale({
x:STAGE.scale().x-1,
y:STAGE.scale().y-1
});
STAGE.batchDraw();
}
}
});
Can you help ? Many thanks.