Skip to content

Commit

Permalink
Merge pull request #6 from mikolalysenko/passive-events
Browse files Browse the repository at this point in the history
Prevent page scrolling
  • Loading branch information
dy authored Jan 30, 2018
2 parents d04d428 + f3b37a3 commit b5f1dd6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b5f1dd6

Please sign in to comment.