From 04c6dc89bb7a8d1bd7c43b6826e27f52cabfd32e Mon Sep 17 00:00:00 2001 From: Deardrops Date: Fri, 8 Sep 2017 01:25:34 +0800 Subject: [PATCH] Fix wrong touch area in mobile chrome (#10) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 fix wrong touch area in mobile chrome * 🐛 add reference about issue #44 --- index.html | 1 + lib/ployfill.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 lib/ployfill.js diff --git a/index.html b/index.html index d65d1a4..a645cc5 100644 --- a/index.html +++ b/index.html @@ -226,6 +226,7 @@ + diff --git a/lib/ployfill.js b/lib/ployfill.js new file mode 100644 index 0000000..7e95b7e --- /dev/null +++ b/lib/ployfill.js @@ -0,0 +1,26 @@ +'use strict' + +// fix issue webxoss/webxoss-core#44 - wrong touch area in mobile chrome +// issue discussion in Easel.js - https://github.com/CreateJS/EaselJS/issues/598#issuecomment-176299538 +// learn more about this bug - https://bugs.chromium.org/p/chromium/issues/detail?id=489206 +// fix method reference - https://stackoverflow.com/questions/41841704/ + +var mobileDevice = /Android|iPhone|/i.test(navigator.userAgent) +var chromeVersion = +(navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./) || [])[2]; + +if (mobileDevice && chromeVersion && chromeVersion < 61) { + try { + Object.defineProperty(window, 'pageXOffset', { + get: function() { + return -document.documentElement.getBoundingClientRect().left; + }, + }); + Object.defineProperty(window, 'pageYOffset', { + get: function() { + return -document.documentElement.getBoundingClientRect().top; + }, + }); + } catch (e) { + console.error(e); + } +}