forked from Clouda-team/touch.code.baidu.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
134 lines (110 loc) · 3.18 KB
/
index.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
touch.on(document, 'DOMContentLoaded', function(){
var $ = function(id){
return document.getElementById(id);
}
var play = $("play"),
code = $("code");
function refreshDemo(){
play.innerHTML = '<img class="target" src="images/cloud.png">';
code.innerHTML = "";
}
var demos = {
rotate : function(){
refreshDemo();
var target = play.querySelector(".target");
},
scale : function(){
refreshDemo();
var target = play.querySelector(".target");
touch.on(target, 'touchstart', function(ev){
ev.originEvent.preventDefault();
});
var initialScale = 1;
touch.on(target, 'pinch', function(ev){
var currentScale = ev.scale - 1;
currentScale = initialScale + currentScale;
if(ev.fingerStatus === 'end'){
initialScale += (ev.scale - 1);
initialScale = initialScale > 2.5 ? 2.5 : initialScale;
}
currentScale = currentScale > 2.5 ? 2.5 : currentScale;
currentScale = currentScale < 1 ? 1 : currentScale;
this.style.webkitTransform = 'scale(' + currentScale + ')';
});
},
tap : function(){
refreshDemo();
var target = play.querySelector(".target");
},
swipe : function(){
refreshDemo();
var target = play.querySelector(".target");
},
drag : function(){
refreshDemo();
var target = play.querySelector(".target");
},
touch : function(){
refreshDemo();
var target = play.querySelector(".target");
}
}
/*
var navlist = document.querySelector("#navlist");
var arrow = document.querySelector("#nav #arrow");
navlist.classList.add("hide");
navlist.show = function(){
navlist.classList.remove("hide");
arrow.classList.add("up");
}
navlist.hide = function(){
navlist.classList.add("hide");
arrow.classList.remove("up");
}
touch.on('#nav #entry', 'touchstart', function(){
var isHide = navlist.classList.contains("hide");
isHide ? navlist.show() : navlist.hide();
});
//rotation
var angle = 30;
touch.on('#rotation .target', 'touchstart', function(ev){
ev.startRotate();
ev.originEvent.preventDefault();
});
touch.on('#rotation .target', 'rotate', function(ev){
var totalAngle = angle + ev.rotation;
if(ev.fingerStatus === 'end'){
angle = angle + ev.rotation;
}
this.style.webkitTransform = 'rotate(' + totalAngle + 'deg)';
});
//scale
touch.on('#scale .target', 'touchstart', function(ev){
ev.originEvent.preventDefault();
});
var initScale = 1;
touch.on('#scale .target', 'pinch', function(ev){
var scale = initScale + ev.scale - 1
if(ev.fingerStatus === 'end'){
initScale += (ev.scale - 1);
initScale = initScale > 2.5 ? 2.5 : initScale;
}
scale = scale > 2.5 ? 2.5 : scale;
scale = scale < 1 ? 1 : scale;
this.style.webkitTransform = 'scale(' + scale + ')';
}); */
//rotation
var angle = -30;
document.querySelector('#demo .target').style.webkitTransform = 'rotate(-30deg)';
touch.on('#demo .target', 'touchstart', function(ev){
ev.startRotate();
ev.originEvent.preventDefault();
});
touch.on('#demo .target', 'rotate', function(ev){
var totalAngle = angle + ev.rotation;
if(ev.fingerStatus === 'end'){
angle = angle + ev.rotation;
}
this.style.webkitTransform = 'rotate(' + totalAngle + 'deg)';
});
});