Skip to content

Commit

Permalink
Fix zoom in/out buttons to scale 2x
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarciabriseno committed Jan 31, 2024
1 parent 71278b1 commit 97b7127
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions resources/js/Viewport/Helper/HelioviewerZoomer.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
* @param {number} duration Length of animation in seconds
*/
_animateZoom(factor, duration) {
clearInterval(this._animate_interval);
// Compute animation frame details.
let fps = 120;
let frame_delay = 1/fps;
Expand All @@ -278,24 +279,31 @@
let frame_delta = delta_scale / num_frames;

let ticks = 0;
let interval = setInterval(() => {
this._animate_interval = setInterval(() => {
let lastScale = this._scale;
this.setScale(this._scale + frame_delta);
if ((factor > 1) && (this._scale < lastScale)) {
frame_delta /= 2;
}
if ((factor < 1) && (this._scale > lastScale)) {
frame_delta *= 2;
}
ticks += 1;
if (ticks == num_frames) { clearInterval(interval); }
if (ticks == num_frames) { clearInterval(this._animate_interval); }
}, frame_delay)
}

/**
* Executed when the zoom in button is clicked.
*/
_smoothZoomIn() {
this._animateZoom(2, 0.25);
this._animateZoom(2, 0.2);
}

/**
* Executed when the zoom out button is clicked.
*/
_smoothZoomOut() {
this._animateZoom(0.5, 0.25);
this._animateZoom(0.5, 0.2);
}
};

0 comments on commit 97b7127

Please sign in to comment.