Skip to content

Loading…

Fix for getting correct client X/Y coords when touch supported #315

Closed
wants to merge 3 commits into from

2 participants

@sjpemberton

Quick fix to help touch supported devices when canvas is NOT in a scrolled container.

@kangax
Owner

Why don't we use fabric.isTouchSupported instead?

@sjpemberton

Hey Kangax,

All I did was copy the old method contents from PointerX/Y when isTouchSupported is true.

As we always use the event.clientX/Y coords now, I didn't see the need to explicitly check for touch support before hand.
Of course there's no harm in it so can add it in if you like.

Either way we still need to find away of handling scrolling parents when isTouchSupported is true.
I have a feeling the scroll always takes priority.

@sjpemberton

No need for this with the recent 9.30 build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Showing with 10 additions and 4 deletions.
  1. +5 −2 dist/all.js
  2. +5 −2 src/util/dom_event.js
View
7 dist/all.js
@@ -2659,9 +2659,12 @@ fabric.util.string = {
scrollTop += element.scrollTop || 0;
}
+ var clientX = event.touches && event.touches[0] && event.touches[0].pageX || event.clientX;
+ var clientY = event.touches && event.touches[0] && event.touches[0].pageY || event.clientY;
+
return {
- x: event.clientX + scrollLeft,
- y: event.clientY + scrollTop
+ x: clientX + scrollLeft,
+ y: clientY + scrollTop
};
}
View
7 src/util/dom_event.js
@@ -193,9 +193,12 @@
scrollTop += element.scrollTop || 0;
}
+ var clientX = event.touches && event.touches[0] && event.touches[0].pageX || event.clientX;
+ var clientY = event.touches && event.touches[0] && event.touches[0].pageY || event.clientY;
+
return {
- x: event.clientX + scrollLeft,
- y: event.clientY + scrollTop
+ x: clientX + scrollLeft,
+ y: clientY + scrollTop
};
}
Something went wrong with that request. Please try again.