Skip to content

Commit

Permalink
Use consistent type for mouseWheelZoom option
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorejb committed Nov 8, 2023
1 parent 84d5935 commit 4a98474
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ Enables adding a class of your choosing to the container for custom styling.

### `mouseWheelZoom`

Type: `boolean | "ctrl"`
Default value: `true`
Type: `"off" | "on" | "ctrl"`
Default value: `"on"`

If set to `false`, the mouse wheel cannot be used to zoom in and out of the image. If set to `"ctrl"`, the mouse wheel will only zoom in and out while the CTRL key is pressed.
If set to `"off"`, the mouse wheel cannot be used to zoom in and out of the image. If set to `"ctrl"`, the mouse wheel will only zoom in and out while the CTRL key is pressed.

### `viewport`

Expand Down
19 changes: 7 additions & 12 deletions cropt.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,27 +582,22 @@ export class Cropt {
* @param {WheelEvent} ev
*/
let scroll = (ev) => {
var delta;
const optionVal = this.options.mouseWheelZoom;
let delta = 0;

if (this.options.mouseWheelZoom === 'ctrl' && ev.ctrlKey !== true){
return;
if (optionVal === 'off' || optionVal === 'ctrl' && !ev.ctrlKey) {
return;
} else if (ev.deltaY) {
delta = ev.deltaY * -1 / 2000;
} else {
delta = 0;
}

var targetZoom = this._currentZoom + (delta * this._currentZoom);
ev.preventDefault();
this.#setZoomerVal(targetZoom);
this.#setZoomerVal(this._currentZoom + (delta * this._currentZoom));
change();
};

this.elements.zoomer.addEventListener('input', change);

if (this.options.mouseWheelZoom) {
this.elements.boundary.addEventListener('wheel', scroll);
}
this.elements.boundary.addEventListener('wheel', scroll);
}

/**
Expand Down Expand Up @@ -741,7 +736,7 @@ export class Cropt {
}

#updateZoomLimits() {
var maxZoom = 1,
var maxZoom = 0.85,
initialZoom,
defaultInitialZoom,
zoomer = this.elements.zoomer,
Expand Down

0 comments on commit 4a98474

Please sign in to comment.