Skip to content
This repository was archived by the owner on Feb 11, 2021. It is now read-only.

PEP does not polyfill offsetX and offsetY properties #217

Closed
AlvinStanescu opened this issue Sep 2, 2015 · 7 comments
Closed

PEP does not polyfill offsetX and offsetY properties #217

AlvinStanescu opened this issue Sep 2, 2015 · 7 comments

Comments

@AlvinStanescu
Copy link

Hi everyone,

I'm currently trying to use PEP in Chrome (version 0.3.0) for an implementation already working in IE11 using native PointerEvents and I noticed that the offsetX and offsetY properties are missing from the event.

These could easily be polyfilled by using e.offsetX = e.pageX - e.target.getBoundingClientRect().left and e.offsetY = e.pageY - e.target.getBoundingClientRect().top.

Is this a known issue?

Thanks,
Alvin

@dmethvin
Copy link

Calling getBoundingClientRect() in the event handler like that will force layout if it's dirty, so it should be avoided unless you absolutely know you need the values. See jquery/jquery#2337 for a related discussion.

@stuartpb
Copy link
Contributor

To clarify, offsetX and offsetY are neither standard properties of the PointerEvent interface, nor the MouseEvent interface it inherits from.

@patrickhlauke
Copy link
Collaborator

Well, they are part of the CSSOM View Module's extension to mouse events http://www.w3.org/TR/cssom-view/#extensions-to-the-mouseevent-interface so they are in an indirect way part of the standard properties of the PE interface, as that simply extends the existing mouse interface (which in most? modern browsers includes the extension from CSSOM)

@scottgonzalez
Copy link
Contributor

We can avoid the unnecessary overhead by using Object.defineProperty() since we've abandoned ES3 environments. Users will still need to be aware of the performance hit if they request those values, but at least we can make them work.

@jzaefferer
Copy link
Contributor

Need to check if the suggested polyfill above is correct. Can compare native mouse offsetX/Y with calculated values.

jzaefferer added a commit to jzaefferer/PEP that referenced this issue Oct 31, 2015
WIP: No idea how to write a unit test for this, so for now it only
extends the simple sample.

Tested with the sample on Chrome, Firefox and Safari (all OSX) and
Android 5 (BrowserStack) and iOS 9.1 (iOS Simulator).

Fixes jquery-archive#217
jzaefferer added a commit to jzaefferer/PEP that referenced this issue Oct 31, 2015
WIP: No idea how to write a unit test for this, so for now it only
extends the simple sample.

Tested with the sample on Chrome, Firefox and Safari (all OSX) and
Android 5 (BrowserStack) and iOS 9.1 (iOS Simulator).

Fixes jquery-archive#217
jzaefferer added a commit to jzaefferer/PEP that referenced this issue Nov 2, 2015
WIP: No idea how to write a unit test for this, so for now it only
extends the simple sample.

Tested with the sample on Chrome, Firefox and Safari (all OSX) and
Android 5 (BrowserStack) and iOS 9.1 (iOS Simulator).

Fixes jquery-archive#217
jzaefferer added a commit to jzaefferer/PEP that referenced this issue Nov 3, 2015
WIP: No idea how to write a unit test for this, so for now it only
extends the simple sample.

Tested with the sample on Chrome, Firefox and Safari (all OSX) and
Android 5 (BrowserStack) and iOS 9.1 (iOS Simulator).

Fixes jquery-archive#217
jzaefferer added a commit to jzaefferer/PEP that referenced this issue Dec 2, 2015
WIP: No idea how to write a unit test for this, so for now it only
extends the simple sample.

Tested with the sample on Chrome, Firefox and Safari (all OSX) and
Android 5 (BrowserStack) and iOS 9.1 (iOS Simulator).

Fixes jquery-archive#217
jzaefferer added a commit to jzaefferer/PEP that referenced this issue Dec 2, 2015
WIP: No idea how to write a unit test for this, so for now it only
extends the simple sample.

Tested with the sample on Chrome, Firefox and Safari (all OSX) and
Android 5 (BrowserStack) and iOS 9.1 (iOS Simulator).

Fixes jquery-archive#217
@greggman
Copy link

greggman commented May 19, 2019

Providing offsetX and offsetY would be great but it's a lot harder than it looks.

Here's an example using offsetX and offsetY

https://greggman.github.io/doodles/test/3d-css-and-offsetXY/3d-css-and-offsetXY.html

It seems to work in Chrome and Firefox both on desktop and on mobile (and Safari via mouse events on desktop)

Here's the same thing with the polyfill added

https://greggman.github.io/doodles/test/3d-css-and-offsetXY/3d-css-and-offsetXY-with-polyfill.html

It has 2 issues

  1. because it doesn't handle CSS transforms it doesn't work on iOS Safari

  2. because it adds PointerEvent the code tries to use them but since it can't handle CSS transforms it now fails on Safari Desktop as well.

@patrickhlauke
Copy link
Collaborator

PEP has now entered emeritus status at the OpenJS Foundation. This repository is now archived.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants