Skip to content

Commit

Permalink
Add srcElement
Browse files Browse the repository at this point in the history
  • Loading branch information
dy committed Aug 7, 2019
1 parent 447f1b1 commit 18483b4
Show file tree
Hide file tree
Showing 5 changed files with 1,449 additions and 8 deletions.
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,23 @@ function panZoom (target, cb) {

var impetus

var initX = 0, initY = 0, init = true
var initFn = function (e) { init = true }
var initX = 0, initY = 0, init = true, srcElement
var initFn = function (e) { init = true, srcElement = e.srcElement }
target.addEventListener('mousedown', initFn)
target.addEventListener('touchstart', initFn, hasPassive ? { passive: true } : false)

var lastY = 0, lastX = 0
impetus = new Impetus({
source: target,
update: function (x, y) {
update: function (x, y, ...args) {
if (init) {
init = false
initX = touch.position[0]
initY = touch.position[1]
}

var e = {
srcElement,
target: target,
type: 'mouse',
dx: x - lastX, dy: y - lastY, dz: 0,
Expand All @@ -64,11 +65,13 @@ function panZoom (target, cb) {
friction: .75
})

var isPassive = [window, document, document.documentElement, document.body].indexOf(target) >= 0

//enable zooming
var wheelListener = wheel(target, function (dx, dy, dz, e) {
e.preventDefault()
if (!isPassive) e.preventDefault()
schedule({
srcElement: e.srcElement,
target: target,
type: 'mouse',
dx: 0, dy: 0, dz: dy,
Expand Down Expand Up @@ -104,6 +107,7 @@ function panZoom (target, cb) {
if (!pinch.pinching || !initialCoords) return

schedule({
srcElement: target,
target: target,
type: 'touch',
dx: 0, dy: 0, dz: - (curr - prev) * mult,
Expand Down
Loading

0 comments on commit 18483b4

Please sign in to comment.