Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var scaleBy = 2;
- stage.on('wheel', e => {
- e.evt.preventDefault();
- var oldScale = stage.scaleX();
- var mousePointTo = {
- x: stage.getPointerPosition().x / oldScale - stage.x() / oldScale,
- y: stage.getPointerPosition().y / oldScale - stage.y() / oldScale
- };
- var newScale =
- e.evt.deltaY > 0 ? oldScale * scaleBy : oldScale / scaleBy;
- stage.scale({ x: newScale, y: newScale });
- var newPos = {
- x: -(mousePointTo.x - stage.getPointerPosition().x / newScale) * newScale,
- y: -(mousePointTo.y - stage.getPointerPosition().y / newScale) * newScale
- };
- stage.position(newPos);
- stage.batchDraw();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement