pinch scale for mobile browsers that don't support it (Chrome)
This commit is contained in:
@@ -124,6 +124,7 @@ export default class OnTap {
|
|||||||
|
|
||||||
if (event.touches.length > 1) {
|
if (event.touches.length > 1) {
|
||||||
this.state.pinching = true;
|
this.state.pinching = true;
|
||||||
|
this.state.scaleStart = Math.sqrt(Math.pow(touches[0].pageX - touches[1].pageX, 2) + Math.pow(touches[0].pageY - touches[1].pageY, 2));
|
||||||
clearTimeout(this.state.pressTO);
|
clearTimeout(this.state.pressTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,6 +199,7 @@ export default class OnTap {
|
|||||||
|
|
||||||
if (event.touches.length === 0) {
|
if (event.touches.length === 0) {
|
||||||
this.state.pinching = false;
|
this.state.pinching = false;
|
||||||
|
this.state.scaleStart = null;
|
||||||
this.state.moving = null;
|
this.state.moving = null;
|
||||||
this.state.lastX = null;
|
this.state.lastX = null;
|
||||||
this.state.lastY = null;
|
this.state.lastY = null;
|
||||||
@@ -236,6 +238,10 @@ export default class OnTap {
|
|||||||
if (this.state.tapStartTime) {
|
if (this.state.tapStartTime) {
|
||||||
const touches = [...event.touches];
|
const touches = [...event.touches];
|
||||||
|
|
||||||
|
event.scale = event.scale ? event.scale :
|
||||||
|
touches.length < 2 ? 1 :
|
||||||
|
Math.sqrt(Math.pow(touches[0].pageX - touches[1].pageX, 2) + Math.pow(touches[0].pageY - touches[1].pageY, 2)) / this.state.scaleStart;
|
||||||
|
|
||||||
Object.assign(event, {
|
Object.assign(event, {
|
||||||
offsetX: touches.reduce((memo, touch) => memo + touch.pageX, 0) / touches.length,
|
offsetX: touches.reduce((memo, touch) => memo + touch.pageX, 0) / touches.length,
|
||||||
offsetY: touches.reduce((memo, touch) => memo + touch.pageY, 0) / touches.length,
|
offsetY: touches.reduce((memo, touch) => memo + touch.pageY, 0) / touches.length,
|
||||||
|
|||||||
Reference in New Issue
Block a user