panzoom icon indicating copy to clipboard operation
panzoom copied to clipboard

Add method to api to expose mouse move on panning

Open wjdingman1 opened this issue 5 years ago • 2 comments

Had a unique use case where we had to pan and zoom two separate images in unison.

This changes allows the user to get information about the movement of the mouse during a pan event so they can call sibling components and 'moveTo' that location.

wjdingman1 avatar Feb 06 '20 16:02 wjdingman1

Would just listening to panstart and pan event work for your use case?

This seem equivalent:

let left = panzoom(document.querySelector('.left img'))
let right = panzoom(document.querySelector('.right img'));

let lastX = 0; let lastY = 0;
left.on('panstart', function(e) {
  let start = e.getTransform();
  lastX = start.x; lastY = start.y;
});

left.on('pan', function(e) {
  let current = e.getTransform();
  let dx = current.x - lastX;
  let dy = current.y - lastY;
  lastX = current.x;
  lastY = current.y;
  
  right.moveBy(dx, dy);
});

https://output.jsbin.com/betikus/2 - js fiddle to play.

anvaka avatar Feb 07 '20 05:02 anvaka

Let me check and I'll get back to you, thanks for quick response!

My first intuition is no, since we are using single file vue components and we are communicating between the two with an eventbus. The api change just abstract away a lot of the 'heavy lifting'.

I'll keep you posted though.

Thanks again

On Fri, Feb 7, 2020 at 12:54 AM Andrei Kashcha [email protected] wrote:

Would just listening to panstart and pan event work for your use case?

This seem equivalent:

let left = panzoom(document.querySelector('.left img'))let right = panzoom(document.querySelector('.right img')); let lastX = 0; let lastY = 0;left.on('panstart', function(e) { let start = e.getTransform(); lastX = start.x; lastY = start.y; }); left.on('pan', function(e) { let current = e.getTransform(); let dx = current.x - lastX; let dy = current.y - lastY; lastX = current.x; lastY = current.y;

right.moveBy(dx, dy); });

https://output.jsbin.com/betikus/2 - js fiddle to play.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/anvaka/panzoom/pull/167?email_source=notifications&email_token=AI2QOO374BXRWJRFLNSDPBDRBTZP7A5CNFSM4KRAGZZKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELBZ7JY#issuecomment-583245735, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI2QOOY5IISGTBYN5OOXQNLRBTZP7ANCNFSM4KRAGZZA .

wjdingman1 avatar Feb 07 '20 13:02 wjdingman1