Re: [pointerevents] event.movementX is always zero in pointerup event. (#344)

Ah, interesting. I didn't look to see which spec the properties came, but I certainly would expect them to behave a certain way with pointer events. Namely in my case, I definitely expect movementX to have a value other than zero.

In order to work around the issue that I see (in Chrome at the moment), I need to ignore the `movementX` property, and instead I track deltas my self using only `clientX` and it gets a bit complicated.

Instead of this:

```js
let isDragging = false;

this.scene.addEventListener("pointerdown", (event) => {
 isDragging = true;
});

this.scene.addEventListener("pointermove", (event) => {
 if (!isDragging) return;

 const delta = event.movementX;
 // use delta
});

this.scene.addEventListener("pointerup", (event) => {
 if (!isDragging) return;
 isDragging = false;

 const delta = event.movementX;

 if (delta !== 0) {
  // use delta, etc, to fling the object
 }
});
```

We have to do this: 

```js
// Keeps the last two pointermove clientX values
let xStack = [0, 0];

function addX(x) {
 xStack.shift();
 xStack.push(x);
}

let isDragging = false;

this.scene.addEventListener("pointerdown", (event) => {
 isDragging = true;
 addX(event.clientX);
});

this.scene.addEventListener("pointermove", (event) => {
 if (!isDragging) return;

 const lastX = xStack[1];
 const delta = event.clientX - lastX;
 addX(event.clientX);

 // ... use delta ...
});

this.scene.addEventListener("pointerup", (event) => {
 if (!isDragging) return;
 isDragging = false;

 // We want the second-to-last pointermove's clientX value here, because
 // the current pointerup has the same clientX as the last pointermove event.
 const secondToLastX = xStack[0];
 let delta = event.clientX - secondToLastX;

 if (delta !== 0) {
  // ... use delta ...
 }
});
```

-- 
GitHub Notification of comment by trusktr
Please view or discuss this issue at https://github.com/w3c/pointerevents/issues/344#issuecomment-757397251 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Sunday, 10 January 2021 01:37:42 UTC