Skip to content

Commit

Permalink
Merge pull request #400 from blnvdanil/wheel-reverse-axis
Browse files Browse the repository at this point in the history
Wheel reverse axis
  • Loading branch information
davidfig authored Oct 10, 2022
2 parents c8da029 + 419331d commit 8aa88ef
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/plugins/Drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ export interface IDragOptions {
* @default 20
*/
lineHeight?: number;

/**
* Swap x and y axes when scrolling.
*
* @default false
*/
wheelSwapAxes?: boolean;
}

const DEFAULT_DRAG_OPTIONS: Required<IDragOptions> = {
Expand All @@ -110,6 +117,7 @@ const DEFAULT_DRAG_OPTIONS: Required<IDragOptions> = {
keyToPress: null,
ignoreKeyToPressOnTouch: false,
lineHeight: 20,
wheelSwapAxes: false,
};

/**
Expand Down Expand Up @@ -421,13 +429,16 @@ export class Drag extends Plugin
{
const step = event.deltaMode ? this.options.lineHeight : 1;

const deltas = [event.deltaX, event.deltaY];
const [deltaX, deltaY] = this.options.wheelSwapAxes ? deltas.reverse() : deltas;

if (this.xDirection)
{
this.parent.x += event.deltaX * step * this.options.wheelScroll * this.reverse;
this.parent.x += deltaX * step * this.options.wheelScroll * this.reverse;
}
if (this.yDirection)
{
this.parent.y += event.deltaY * step * this.options.wheelScroll * this.reverse;
this.parent.y += deltaY * step * this.options.wheelScroll * this.reverse;
}
if (this.options.clampWheel)
{
Expand Down

0 comments on commit 8aa88ef

Please sign in to comment.