-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
39 lines (35 loc) · 1.13 KB
/
index.html
File metadata and controls
39 lines (35 loc) · 1.13 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Differentiate Single & Double Mouse Click</title>
</head>
<body>
<button id="button">button</button>
<script type="text/javascript">
var TIME_OFFSET = 300;
var btn, st = null, n = 0;
btn = document.querySelector('button');
btn.addEventListener('click', function(){
n++;
if( n === 1) {
st = window.setTimeout(function(){
someFn1();
n = 0;
}, TIME_OFFSET);
}
else {
someFn2();
clearTimeout(st);
n = 0;
}
});
function someFn1(){
alert('Function executed on single click!');
}
function someFn2(){
alert('Function executed on double click!');
}
</script>
</body>
</html>