zoom to mouse
This commit is contained in:
parent
4a8a9185af
commit
72338ad466
1 changed files with 17 additions and 11 deletions
|
@ -81,8 +81,8 @@ export class Resizer {
|
||||||
// width should be larger
|
// width should be larger
|
||||||
this.viewbox[2] = height_percentage * el.width;
|
this.viewbox[2] = height_percentage * el.width;
|
||||||
} else {
|
} else {
|
||||||
this.viewbox[3] = width_percentage * el.height;
|
|
||||||
// height should be larger
|
// height should be larger
|
||||||
|
this.viewbox[3] = width_percentage * el.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.viewbox[0] -= (this.viewbox[2] - or_width) / 2;
|
this.viewbox[0] -= (this.viewbox[2] - or_width) / 2;
|
||||||
|
@ -147,23 +147,29 @@ export class Resizer {
|
||||||
if (this.hoovering) {
|
if (this.hoovering) {
|
||||||
const delta = e.deltaY > 0 ? 0.1 * this.viewbox[2] : -0.1 * this.viewbox[2];
|
const delta = e.deltaY > 0 ? 0.1 * this.viewbox[2] : -0.1 * this.viewbox[2];
|
||||||
const dx = delta * this.scaleX;
|
const dx = delta * this.scaleX;
|
||||||
|
const dy = delta * this.scaleY;
|
||||||
|
|
||||||
this.viewbox[2] += dx;
|
const mouse_dx = this.mouse_pos[0] / this.el_box[0];
|
||||||
this.viewbox[0] -= dx / 2;
|
const mouse_dy = this.mouse_pos[1] / this.el_box[1];
|
||||||
|
|
||||||
|
this._zoom([dx, dy], [mouse_dx, mouse_dy]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_zoom(deltas: number[], center: number[]) {
|
||||||
|
this.viewbox[2] += deltas[0];
|
||||||
|
this.viewbox[0] -= deltas[0] * center[0];
|
||||||
this.viewbox[2] = Math.min(this.viewbox[2], this.orig_viewbox[2]);
|
this.viewbox[2] = Math.min(this.viewbox[2], this.orig_viewbox[2]);
|
||||||
|
|
||||||
const dy = delta * this.scaleY;
|
this.viewbox[3] += deltas[1];
|
||||||
this.viewbox[3] += dy;
|
this.viewbox[1] -= deltas[1] * center[1];
|
||||||
this.viewbox[1] -= dy / 2;
|
|
||||||
this.viewbox[3] = Math.min(this.viewbox[3], this.orig_viewbox[3]);
|
this.viewbox[3] = Math.min(this.viewbox[3], this.orig_viewbox[3]);
|
||||||
|
|
||||||
this._clip_viewbox();
|
this._clip_viewbox();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
get_viewbox(): number[] {
|
get_viewbox(): number[] {
|
||||||
return this.viewbox;
|
return this.viewbox;
|
||||||
// return [this.viewbox[0] / this.orig_viewbox[0], this.viewbox[1] / this.orig_viewbox[1], this.viewbox[2] / this.orig_viewbox[2], this.viewbox[3] / this.orig_viewbox[3],];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get_mouse_pos(): number[] {
|
get_mouse_pos(): number[] {
|
||||||
|
|
Loading…
Reference in a new issue