From 20317207006909fdb62c1f4b8b95c62dbe9f44e1 Mon Sep 17 00:00:00 2001 From: Matthew Petroff Date: Sat, 3 Mar 2018 20:20:34 -0500 Subject: [PATCH] Fix touch input issue on Chrome for Android (fixes #551). --- src/css/pannellum.css | 1 + src/js/pannellum.js | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/css/pannellum.css b/src/css/pannellum.css index 95ff6fe..2b26090 100644 --- a/src/css/pannellum.css +++ b/src/css/pannellum.css @@ -17,6 +17,7 @@ outline: 0; line-height: 1.4; contain: content; + touch-action: none; } .pnlm-container * { diff --git a/src/js/pannellum.js b/src/js/pannellum.js index 09f12bf..4fdfe70 100644 --- a/src/js/pannellum.js +++ b/src/js/pannellum.js @@ -482,13 +482,17 @@ function onImageLoad() { container.addEventListener('blur', clearKeys, false); } document.addEventListener('mouseleave', onDocumentMouseUp, false); - dragFix.addEventListener('touchstart', onDocumentTouchStart, false); - dragFix.addEventListener('touchmove', onDocumentTouchMove, false); - dragFix.addEventListener('touchend', onDocumentTouchEnd, false); - dragFix.addEventListener('pointerdown', onDocumentPointerDown, false); - dragFix.addEventListener('pointermove', onDocumentPointerMove, false); - dragFix.addEventListener('pointerup', onDocumentPointerUp, false); - dragFix.addEventListener('pointerleave', onDocumentPointerUp, false); + if (document.documentElement.style.pointerAction === '' && + document.documentElement.style.touchAction === '') { + dragFix.addEventListener('pointerdown', onDocumentPointerDown, false); + dragFix.addEventListener('pointermove', onDocumentPointerMove, false); + dragFix.addEventListener('pointerup', onDocumentPointerUp, false); + dragFix.addEventListener('pointerleave', onDocumentPointerUp, false); + } else { + dragFix.addEventListener('touchstart', onDocumentTouchStart, false); + dragFix.addEventListener('touchmove', onDocumentTouchMove, false); + dragFix.addEventListener('touchend', onDocumentTouchEnd, false); + } // Deal with MS pointer events if (window.navigator.pointerEnabled) @@ -928,7 +932,7 @@ function onDocumentPointerMove(event) { pointerCoordinates[i].clientY = event.clientY; event.targetTouches = pointerCoordinates; onDocumentTouchMove(event); - //event.preventDefault(); + event.preventDefault(); return; } }