-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.html
73 lines (66 loc) · 1.91 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Swipe-listener Demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
</head>
<body>
<div id="container">
Swipe Here
</div>
<div id="message"></div>
<script src="dist/swipe-listener.min.js"></script>
<script>
let setMessage = function (msg) {
document.querySelector('#message').innerHTML = msg;
}
let container = document.querySelector('#container');
container.addEventListener('touchstart', function () {
setMessage('');
});
container.addEventListener('mousedown', function () {
setMessage('');
});
var listener = SwipeListener(container);
container.addEventListener('swipe', function (e) {
console.log('swipe', e.detail);
var d = e.detail.directions;
if (d.top) {
if (d.right) {
setMessage('Swiped top-right.');
} else if (d.left) {
setMessage('Swiped top-left.');
} else {
setMessage('Swiped top.');
}
} else if (d.bottom) {
if (d.right) {
setMessage('Swiped bottom-right.');
} else if (d.left) {
setMessage('Swiped bottom-left.');
} else {
setMessage('Swiped bottom.');
}
} else {
if (d.right) {
setMessage('Swiped right.');
} else if (d.left) {
setMessage('Swiped left.');
}
}
});
container.addEventListener('swiping', function (e) {
console.log('swiping', e.detail);
});
container.addEventListener('swiperelease', function (e) {
console.log('swiperelease', e.detail);
});
container.addEventListener('swipecancel', function (e) {
console.log('swipecancel', e.detail);
});
</script>
</body>
</html>