handle.js
999 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {
setTouchState
} from './utils/helper'
export default {
// 图片手势初始监测
touchStart (e) {
const self = this
const [touch0, touch1] = e.touches
if (!self.src) return
setTouchState(self, true, null, null)
// 计算第一个触摸点的位置,并参照改点进行缩放
self.__oneTouchStart(touch0)
// 两指手势触发
if (e.touches.length >= 2) {
self.__twoTouchStart(touch0, touch1)
}
},
// 图片手势动态缩放
touchMove (e) {
const self = this
const [touch0, touch1] = e.touches
if (!self.src) return
setTouchState(self, null, true)
// 单指手势时触发
if (e.touches.length === 1) {
self.__oneTouchMove(touch0)
}
// 两指手势触发
if (e.touches.length >= 2) {
self.__twoTouchMove(touch0, touch1)
}
},
touchEnd (e) {
const self = this
if (!self.src) return
setTouchState(self, false, false, true)
self.__xtouchEnd()
}
}