5

I try to zoom with mousewheel on a Raphael paper using viewBox. Here is the JSFiddle code.

it works but now i want to zoom in the center and i have no idea where to start. I guess i should change the viewBox x and y coordinates. I have tried this (in the function handle(delta)):

x = paper.width - viewBoxWidth;
y = paper.height - viewBoxHeight;
paper.setViewBox(x,y,viewBoxWidth,viewBoxHeight);

but didnt work. I would appreciate any help. Thank you!

mac
  • 42,153
  • 26
  • 121
  • 131
user1085803
  • 51
  • 1
  • 1
  • 2
  • Since your question has been answered on the mailing list I'll paste this here for future reference: https://groups.google.com/forum/#!topic/raphaeljs/K-84cOe8ZP8 – Elbert Alias Dec 11 '11 at 21:46

1 Answers1

4

For Zoom Out:

var tempViewBoxWidth = viewBoxWidth;
var tempViewBoxHeight = viewBoxHeight;

viewBoxWidth /= 1.10;
viewBoxHeight /=1.10;

viewBoxX -= (viewBoxWidth - tempViewBoxWidth) / 2;
viewBoxY -= (viewBoxHeight - tempViewBoxHeight) / 2; 

paper.setViewBox(viewBoxX, viewBoxY, viewBoxWidth, viewBoxHeight, false);
animuson
  • 53,861
  • 28
  • 137
  • 147