- From: Timothy Guan-tin Chien via GitHub <sysbot+gh@w3.org>
- Date: Thu, 13 Feb 2020 20:40:18 +0000
- To: public-css-archive@w3.org
timdream has just created a new issue for https://github.com/w3c/csswg-drafts:
== [css-om-view] MouseEventInit should allow `pageX/Y` ==
The `MouseEvent` [interface](https://drafts.csswg.org/cssom-view/#extensions-to-the-mouseevent-interface) exposes `pageX/Y` but it doesn't allow the constructor to specify `pageX/Y` value.
At least on Safari, the `pageX/Y` value of a constructed MouseEvent (and sub-class instances) will simply be the fix to the value specified in `clientX/Y`, disregarding the scrolling position of the parent elements when dispatched.
My use case for `pageX/Y` is to be able to test the event consumption of my own script on the element. I had to result to use something like this:
```javascript
const rect = targetElement.getBoundingClientRect();
let event = new WheelEvent("wheel", {
// WheelEventInit
deltaX: 0,
deltaY: 4 * (invert ? -1 : 1),
deltaZ: 0,
deltaMode: WheelEvent.DOM_DELTA_PIXEL,
// MouseEventInit
clientX: rect.x + rect.width / 2,
clientY: rect.y + rect.height / 2
});
Object.defineProperty(event, "pageX", { value: rect.x + rect.width / 2 });
Object.defineProperty(event, "pageY", { value: document.scrollingElement.scrollTop + rect.y + rect.height / 2 });
targetElement.dispatchEvent(event);
```
It will be merrier to be able to specify `clientX/Y` directly on `MouseEventInit`.
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4775 using your GitHub account
Received on Thursday, 13 February 2020 20:40:20 UTC