After many attempts, searching and trying using the @Eric Rowell tooltip and the code posted in the SO question Zoom in (using scale and translation) Finally, I got the zoom in and out of a fixed point using KineticJS .
This is where DEMO works.
And here is the code:
var ui = { stage: null, scale: 1, zoomFactor: 1.1, origin: { x: 0, y: 0 }, zoom: function(event) { event.preventDefault(); var evt = event.originalEvent, mx = evt.clientX , my = evt.clientY , wheel = evt.wheelDelta / 120; var zoom = (ui.zoomFactor - (evt.wheelDelta < 0 ? 0.2 : 0)); var newscale = ui.scale * zoom; ui.origin.x = mx / ui.scale + ui.origin.x - mx / newscale; ui.origin.y = my / ui.scale + ui.origin.y - my / newscale; ui.stage.setOffset(ui.origin.x, ui.origin.y); ui.stage.setScale(newscale); ui.stage.draw(); ui.scale *= zoom; } }; $(function() { var width = $(document).width() - 2, height = $(document).height() - 5; var stage = ui.stage = new Kinetic.Stage({ container: 'container', width: width, height: height }); var layer = new Kinetic.Layer({ draggable: true }); var rectX = stage.getWidth() / 2 - 50; var rectY = stage.getHeight() / 2 - 25; var box = new Kinetic.Circle({ x: 100, y: 100, radius: 50, fill: '#00D200', stroke: 'black', strokeWidth: 2, });
juan.facorro
source share