Skip to content

Instantly share code, notes, and snippets.

@williammustaffa
Created June 27, 2019 11:57
Show Gist options
  • Save williammustaffa/c68137762359bac7e9196a9b02be9471 to your computer and use it in GitHub Desktop.
Save williammustaffa/c68137762359bac7e9196a9b02be9471 to your computer and use it in GitHub Desktop.
PinchZoom.prototype.getContainerCenter = function () {
var centerX = this.container.offsetLeft + this.container.offsetWidth / 2;
var centerY = this.container.offsetTop + this.container.offsetHeight / 2;
return {
x: centerX,
y: centerY,
};
};
PinchZoom.prototype.zoomTo = function (zoomFactor) {
var center = this.getContainerCenter();
var startZoomFactor = this.zoomFactor;
var updateProgress = (function (progress) {
this.scaleTo(startZoomFactor + progress * (zoomFactor - startZoomFactor), center);
}).bind(this);
this.animate(this.options.animationDuration, updateProgress, this.swing);
};
PinchZoom.prototype.zoomIn = function () {
this.zoomTo(2);
};
PinchZoom.prototype.zoomOut = function () {
// Reset Zoom
this.zoomOutAnimation();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment