Skip to content

Commit

Permalink
Measure redispatch to root when has root (#8)
Browse files Browse the repository at this point in the history
* Redispatch pointermove events to root when has root

* 0.4.0
  • Loading branch information
ydaniv authored Jan 12, 2025
1 parent d002a30 commit da566fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kuliso",
"version": "0.3.2",
"version": "0.4.0",
"sideeffects": true,
"description": "Tiny library for performant pointer-driven or gyroscope-driven effects",
"main": "dist/index.cjs",
Expand Down
25 changes: 24 additions & 1 deletion src/Pointer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class Pointer {
this.previousProgress = { ...this.progress };
this.currentProgress = null;

this._measure = (event) => {
const _measure = (event) => {
Object.assign(this.previousProgress, this.currentProgress || this.progress);

this.progress.x = this.config.root ? event.offsetX : event.x;
Expand All @@ -71,6 +71,29 @@ export class Pointer {
this.progress.vy = event.movementY;
this._nextTick = trigger();
};

const dpr = window.devicePixelRatio;

if (this.config.root) {
this._measure = (e) => {
if (e.target !== this.config.root) {
const event = new PointerEvent('pointermove', {
bubbles: true,
cancelable: true,
clientX: e.x * dpr,
clientY: e.y * dpr
});

e.stopPropagation();

this.config.root.dispatchEvent(event);
} else {
_measure(e);
}
}
} else {
this._measure = _measure;
}
}

/**
Expand Down

0 comments on commit da566fe

Please sign in to comment.