Advertisement
Guest User

Untitled

a guest
Dec 27th, 2019
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.        var scaleBy = 2;
  2.             stage.on('wheel', e => {
  3.                 e.evt.preventDefault();
  4.                 var oldScale = stage.scaleX();
  5.  
  6.                 var mousePointTo = {
  7.                     x: stage.getPointerPosition().x / oldScale - stage.x() / oldScale,
  8.                     y: stage.getPointerPosition().y / oldScale - stage.y() / oldScale
  9.                 };
  10.  
  11.                 var newScale =
  12.                     e.evt.deltaY > 0 ? oldScale * scaleBy : oldScale / scaleBy;
  13.                 stage.scale({ x: newScale, y: newScale });
  14.  
  15.                 var newPos = {
  16.                     x: -(mousePointTo.x - stage.getPointerPosition().x / newScale) * newScale,
  17.                     y: -(mousePointTo.y - stage.getPointerPosition().y / newScale) * newScale
  18.                 };
  19.  
  20.                 stage.position(newPos);
  21.                 stage.batchDraw();
  22.             });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement