From a27f76397abbd24895ee9ea63daeeea17f66e88b Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Tue, 16 Oct 2018 00:39:09 +0100 Subject: [PATCH] Fixing 'container' scaleTo --- src/components/Output/custom-els/PinchZoom/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/Output/custom-els/PinchZoom/index.ts b/src/components/Output/custom-els/PinchZoom/index.ts index d36ad919..101407b0 100644 --- a/src/components/Output/custom-els/PinchZoom/index.ts +++ b/src/components/Output/custom-els/PinchZoom/index.ts @@ -145,7 +145,7 @@ export default class PinchZoom extends HTMLElement { const relativeToEl = (relativeTo === 'content' ? this._positioningEl : this); // No content element? Fall back to just setting scale - if (!relativeToEl) { + if (!relativeToEl || !this._positioningEl) { this.setTransform({ scale, allowChangeEvent }); return; } @@ -157,6 +157,10 @@ export default class PinchZoom extends HTMLElement { if (relativeTo === 'content') { originX += this.x; originY += this.y; + } else { + const currentRect = this._positioningEl.getBoundingClientRect(); + originX -= currentRect.left; + originY -= currentRect.top; } this._applyChange({