From f3b37a32809b42177a9ecec176eda9e0837b14fe Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 26 Jan 2018 14:25:14 -0500 Subject: [PATCH] Prevent page scrolling --- camera.js | 15 ++++++++++++--- package.json | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/camera.js b/camera.js index c8f5711..55b32b3 100644 --- a/camera.js +++ b/camera.js @@ -7,6 +7,7 @@ var createView = require('3d-view') var mouseChange = require('mouse-change') var mouseWheel = require('mouse-wheel') var mouseOffset = require('mouse-event-offset') +var hasPassive = require('has-passive-events') function createCamera(element, options) { element = element || document.body @@ -171,15 +172,23 @@ function createCamera(element, options) { var xy = mouseOffset(ev.changedTouches[0], element) handleInteraction(0, xy[0], xy[1], lastMods) handleInteraction(1, xy[0], xy[1], lastMods) - }) + + ev.preventDefault() + }, hasPassive ? {passive: false} : false) + element.addEventListener('touchmove', function (ev) { var xy = mouseOffset(ev.changedTouches[0], element) handleInteraction(1, xy[0], xy[1], lastMods) - }) + + ev.preventDefault() + }, hasPassive ? {passive: false} : false) + element.addEventListener('touchend', function (ev) { var xy = mouseOffset(ev.changedTouches[0], element) handleInteraction(0, lastX, lastY, lastMods) - }) + + ev.preventDefault() + }, hasPassive ? {passive: false} : false) function handleInteraction (buttons, x, y, mods) { var scale = 1.0 / element.clientHeight diff --git a/package.json b/package.json index a9cf81a..64fde6c 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ }, "dependencies": { "3d-view": "^2.0.0", + "has-passive-events": "^1.0.0", "mouse-change": "^1.1.1", "mouse-event-offset": "^3.0.2", "mouse-wheel": "^1.0.2",