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

offsetX, offsetY are not correct in Firefox, Opera, Chrome mobile #41

Closed
dylang opened this issue Feb 28, 2013 · 9 comments
Closed

offsetX, offsetY are not correct in Firefox, Opera, Chrome mobile #41

dylang opened this issue Feb 28, 2013 · 9 comments

Comments

@dylang
Copy link

dylang commented Feb 28, 2013

When pointerevents fire the only way to get the location relative to the target element is offsetX and offsetY.

These values appear to be 0 in some browsers.

Working correctly:

  • Firefox for desktop
  • Safari for desktop

Wrong values:

  • Chrome beta for Android

Always zero:

  • Firefox
  • Opera

Not tested:

  • Any IE
  • Mobile Safari
@dylang
Copy link
Author

dylang commented Feb 28, 2013

There's strong chance I'm wrong about Chrome Beta for Android having incorrect values but I'm not able to re-test it right now.

@dfreedm
Copy link
Contributor

dfreedm commented Mar 1, 2013

It looks like offsetX and offsetY are deprecated, or non standard event properties.

They can't be set through initMouseEvent, nor in an Event constructor.

Therefore, if they are even set correctly, that seems to be a platform decision that I can't replicate in Javascript.

@dylang
Copy link
Author

dylang commented Mar 3, 2013

Totally agree with your findings but sad to learn offsetX and offsetY are not in the spec.

Figuring out where an event happens relative to the target object is extremely helpful for drawing applications, drag and drop, and probably many other use cases. It's not too difficult to calculate manually, but any extra code is an opening for silly bugs like box model differences.

I think this can be closed.

@dfreedm dfreedm closed this as completed Mar 4, 2013
@jacobrossi
Copy link

Actually, this is standardized in CSS OM View: http://www.w3.org/TR/cssom-view/#extensions-to-the-mouseevent-interface

We should add these as they're very helpful.

@arschmitz arschmitz reopened this Apr 20, 2015
@arschmitz
Copy link
Contributor

Agreed we should fix this i'm going to re open this issue

@patrickhlauke
Copy link
Collaborator

I believe Firefox only recently implemented these? https://bugzilla.mozilla.org/show_bug.cgi?id=69787

@arschmitz
Copy link
Contributor

These have worked in firefox for a long time. We have used them in the jQuery Mobile swipe events for years and you can see in the original issue above the reporter says firefox is working correctly.

However there are some browser issues we work around with them in jQuery Mobile https://github.com/jquery/jquery-mobile/blob/master/js/events/touch.js#L117-L142

@arschmitz
Copy link
Contributor

@patrickhlauke Hmm that bug thread does sound that way though, and re reading the description they say works fine firefox desktop, but below for just "firefox" it says always zero. This is very confusing...

@jzaefferer
Copy link
Contributor

While this ticket is older, #217 has pretty much the same discussion and a potential solution. Closing this as a duplicate.

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

No branches or pull requests

6 participants