forked from eracom-gr361/exemples-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gestures.html
231 lines (178 loc) · 6.89 KB
/
gestures.html
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!doctype html>
<html>
<head>
<title>gestures</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: "Roboto Mono", sans-serif;
padding: 1em;
}
button {
clear: left;
font-size: 120%;
display: block;
margin: 0 0 0.5em 0;
padding: 0.2em;
border: 1px solid #aaa;
background-color: #ddd;
line-height: 1.3;
}
.events, .observations {
border: 1px solid gray;
margin: 1.5em 0 0 0;
padding: 1em;
max-width: 50em;
}
ul {
padding-left: 1.5em;
}
h1 {
margin: 0;
font-size: 120%;
}
.hover:hover {
background: yellow;
}
.focus:focus {
background: yellow;
}
@media screen and (min-width: 40em) {
.events {
position: absolute;
top: 0em;
right: 2em;
}
button {
font-size: 200%;
}
}
@media screen and (min-width: 60em) {
.events {
width: 50%
}
}
</style>
</head>
<body>
<button type="button" class="click">js:click</button>
<button type="button" class="mouseover">js:mouseover/out</button>
<button type="button" class="mouseenter">js:mouseenter/leave</button>
<button type="button" class="jsfocus">js:focus/blur</button>
<button type="button" class="hover">css:hover</button>
<button type="button" class="focus">css:focus</button>
<div class="events">
<h1>JavaScript Events:</h1>
<ul class="status">
<li>js clicks: <span class="clicks">0</span></li>
<li>js mouseOvers: <span class="hovers">0</span></li>
<li>js mouseOuts: <span class="exits">0</span></li>
<li>js mouseEnters: <span class="enters">0</span></li>
<li>js mouseLeaves: <span class="leaves">0</span></li>
<li>js focus: <span class="focuses">0</span></li>
<li>js blur: <span class="blurs">0</span></li>
</ul>
</div>
<div class="observations">
<h1>Observations:</h1>
<ul>
<li><b>js:click</b> = fonctionne parfaitement sur tablette iOS.</li>
<li><b>js:mouseover</b> = fonctionne sur tablette iOS comme un click. Le mouseout se produit lorsqu'on touche un autre élément cliquable.</li>
<li><b>js:focus/blur</b> = l'évenement n'est pas capté, aucun effet sur tablette iOS.</li>
<li><b>css:hover</b> = fonctionne sur tablette iOS comme js:mouseover/mouseout - le hover reste actif jusqu'à ce qu'on touche un autre élément cliquable.</li>
<li><b>css:focus</b> = pas d'effet visible sur tablette iOS. Voir <a href="http://stackoverflow.com/questions/3885018/active-pseudo-class-doesnt-work-in-mobile-safari">stackoverflow</a></li>
Note sur iOS: "the :active pseudo state is triggered only when there is a touch event set on the HTML element—for example, when ontouchstart is set on the element."
</ul>
</div>
<script>
// On mesure les clics :
document.querySelector(".click").addEventListener(
"click", clicking, false
);
var NumberOfClicks = 0;
// On mesure les mouseover / mouseout :
document.querySelector(".mouseover").addEventListener(
"mouseover", mousingOver, false
);
document.querySelector(".mouseover").addEventListener(
"mouseout", mousingOut, false
);
var NumberOfHovers = 0;
var NumberOfExits = 0;
// On mesure les MouseEnter / MouseLeave :
/*
*
* https://developer.mozilla.org/en/docs/Web/Events/mouseenter
* http://api.jquery.com/mouseover/
mouseenter = Similar to mouseover, it differs in that
it doesn't bubble and that it isn't sent
when the pointer is moved from one of its descendants'
physical space to its own physical space.
With deep hierarchies, the amount of mouseenter events sent
can be quite huge and cause significant performance problems.
In such cases, it is better to listen for mouseover events.
*/
document.querySelector(".mouseenter").addEventListener(
"mouseenter", mouseEntering, false
);
document.querySelector(".mouseenter").addEventListener(
"mouseleave", mouseLeaving, false
);
var NumberOfEnters = 0;
var NumberOfLeaves = 0;
// focus and blur
// On mesure les focus :
document.querySelector(".jsfocus").addEventListener(
"focus", focussing, false
);
var NumberOfFocuses = 0;
// On mesure les blur :
document.querySelector(".jsfocus").addEventListener(
"blur", blurring, false
);
var NumberOfBlurs = 0;
document.querySelector(".jsfocus").ontouchstart;
// mousedown,
// mousemove,
// mouseout,
// mouseover,
// mouseup
function clicking(KeyEvent) {
NumberOfClicks++;
document.querySelector(".clicks").innerHTML = NumberOfClicks;
}
function mousingOver(KeyEvent) {
event.target.style.backgroundColor = "yellow";
NumberOfHovers++;
document.querySelector(".hovers").innerHTML = NumberOfHovers;
}
function mousingOut(KeyEvent) {
event.target.style.backgroundColor = "#ddd";
NumberOfExits++;
document.querySelector(".exits").innerHTML = NumberOfHovers;
}
function mouseEntering(KeyEvent) {
event.target.style.backgroundColor = "yellow";
NumberOfEnters++;
console.log(NumberOfEnters);
document.querySelector(".enters").innerHTML = NumberOfEnters;
}
function mouseLeaving(KeyEvent) {
event.target.style.backgroundColor = "#ddd";
NumberOfLeaves++;
document.querySelector(".leaves").innerHTML = NumberOfLeaves;
}
function focussing(KeyEvent) {
event.target.style.backgroundColor = "yellow";
NumberOfFocuses++;
document.querySelector(".focuses").innerHTML = NumberOfFocuses;
}
function blurring(KeyEvent) {
event.target.style.backgroundColor = "#ddd";
NumberOfBlurs++;
document.querySelector(".blurs").innerHTML = NumberOfBlurs;
}
</script>
</body>
</html>