forked from hammerjs/hammer.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
no-jquery.html
104 lines (83 loc) · 2.65 KB
/
no-jquery.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
<!DOCTYPE html>
<html>
<head>
<title>Hammer.js</title>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
<style>
@keyframes highlight {
0%{ background: rgba(255, 240, 140, 1); }
100%{ background: rgba(255, 240, 140, 0); }
}
@-moz-keyframes highlight{
0%{ background: rgba(255, 240, 140, 1); }
100%{ background: rgba(255, 240, 140, 0); }
}
@-webkit-keyframes highlight{
0%{ background: rgba(255, 240, 140, 1); }
100%{ background: rgba(255, 240, 140, 0); }
}
body { padding: 0; }
#container {
padding: 20px;
}
.highlight {
background: #fff68d;
}
.hero-unit {
padding: 0;
}
#toucharea {
padding: 30px;
}
</style>
</head>
<body>
<div id="container">
<div class="page-header">
<h1>jquery.hammer.js without jquery, for save full loading</h1>
</div>
<div class="hero-unit">
<div id="toucharea">
<h1>Touch me</h1>
<p>The tap event will be fired. Notice in the sourcecode that event delegation is also supported.<br>
In the console you can see the event data.</p>
<h4>List items with stopPropagation</h4>
<ul id="items">
<li>List item 1</li>
<li>List item 2</li>
<li>List item 3</li>
<li>List item 4</li>
<li>List item 5</li>
</ul>
<p>
<a href="#" id="add-list-item" class="btn btn-success">Add list item</a>
</p>
</div>
</div>
</div>
<script src="../dist/jquery.hammer.js"></script>
<script>
function highlight(el) {
setTimeout(function() {
el.className = el.className.replace("highlight", "");
}, 100);
el.className = el.className + " highlight";
}
var hammertime = Hammer(document.getElementById("toucharea"));
console.log(hammertime);
// the whole area
hammertime.on("tap swipeleft drag", function(ev) {
if(window.console) { console.log(ev); }
highlight(this);
});
// on elements in the toucharea, with a stopPropagation
hammertime.on("tap swipe", function(ev) {
if(window.console) { console.log('nested', ev); }
highlight(this);
ev.stopPropagation();
});
</script>
<script src="assets/js/ga.js"></script>
</body>
</html>