@@ -25,15 +25,15 @@ var pivot = {
25
25
26
26
// 判断当前设备是否为触摸屏
27
27
function isTouchDevice ( ) {
28
- return window . matchMedia ( "(pointer: coarse)" ) . matches ;
28
+ return window . matchMedia ( "(pointer: coarse)" ) . matches ;
29
29
}
30
30
31
31
// 计算屏幕中心
32
32
function getScreenCenter ( ) {
33
- return {
34
- x : window . innerWidth / 2 ,
35
- y : window . innerHeight / 2
36
- } ;
33
+ return {
34
+ x : window . innerWidth / 2 ,
35
+ y : window . innerHeight / 2
36
+ } ;
37
37
}
38
38
39
39
// // 设置 pivot 点
56
56
clientY : 300
57
57
} ) ;
58
58
59
-
59
+ //set up start touch
60
+ window . addEventListener ( "touchstart" , draw )
60
61
61
62
// set up start drag event
62
63
window . addEventListener ( "mousedown" , draw ) ;
@@ -75,14 +76,14 @@ function draw(e) {
75
76
}
76
77
77
78
function aim ( e ) {
78
- try { e . preventDefault ( ) ; } catch ( e ) { }
79
+ try { e . preventDefault ( ) ; } catch ( e ) { }
79
80
// get mouse position in relation to svg position and scale
80
81
var point = getMouseSVG ( e ) ;
81
82
point . x = Math . min ( point . x , pivot . x - 7 ) ;
82
83
point . y = Math . max ( point . y , pivot . y + 7 ) ;
83
84
var dx = point . x - pivot . x ;
84
85
var dy = point . y - pivot . y ;
85
-
86
+
86
87
// Make it more difficult by adding random angle each time
87
88
var angle = Math . atan2 ( dy , dx ) + randomAngle ;
88
89
var bowAngle = angle - Math . PI ;
@@ -118,7 +119,7 @@ function aim(e) {
118
119
attr : {
119
120
d : "M100,250c" + offset . x + "," + offset . y + "," + ( arcWidth - offset . x ) + "," + ( offset . y + 50 ) + "," + arcWidth + ",50"
120
121
} ,
121
- autoAlpha : distance / 60
122
+ autoAlpha : distance / 60
122
123
} ) ;
123
124
124
125
}
@@ -226,8 +227,15 @@ function showMessage(selector) {
226
227
227
228
function getMouseSVG ( e ) {
228
229
// normalize mouse position within svg coordinates
229
- cursor . x = e . clientX ;
230
- cursor . y = e . clientY ;
230
+ if ( e . touches ) { //如果是触摸
231
+ cursor . x = e . touches [ 0 ] . pageX ;
232
+ cursor . y = e . touches [ 0 ] . pageY ;
233
+ } else { //如果是鼠标
234
+ cursor . x = e . clientX ;
235
+ cursor . y = e . clientY ;
236
+ }
237
+
238
+
231
239
return cursor . matrixTransform ( svg . getScreenCTM ( ) . inverse ( ) ) ;
232
240
}
233
241
0 commit comments