forked from desandro/draggabilly
-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.html
197 lines (154 loc) · 4.29 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
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Draggabilly</title>
<style>
.box {
width: 100px;
height: 100px;
background: red;
}
#ex1 {
position: relative;
left: 200px;
top: 50px;
}
#ex2 {
background: blue;
}
#has-handles {
position: relative;
left: 240px;
top: 100px;
background: orange;
}
.handle {
background: #666;
position: absolute;
width: 40px;
height: 40px;
}
#has-handles .handle2 {
right: 10px;
bottom: 10px;
}
.is-dragging {
opacity: 0.5;
/* hack for artifacts http://stackoverflow.com/a/12023155 */
-webkit-backface-visibility: hidden;
}
.container {
border: 1px solid;
position: relative;
}
.container:after {
content: '';
display: block;
clear: both;
}
#container1 {
width: 150px;
}
#container1 .box {
float: left;
margin: 5px;
width: 38px;
height: 38px;
border: 1px solid;
background: orange;
}
#kitties {
background: #CCC;
width: 140px;
padding: 10px;
}
</style>
</head>
<body>
<h1>Draggabilly</h1>
<p>Press [B] to enable/disable the blue draggabilly</p>
<div id="ex1" class="box">
<div class="handle"></div>
</div>
<div id="ex2" class="box"></div>
<div id="has-handles" class="box">
<div class="handle handle1"></div>
<div class="handle handle2"></div>
</div>
<div id="container1" class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<img id="kitten" src="http://placekitten.com/100/100" />
<div id="kitties">
<img src="http://placekitten.com/40/60" />
<img src="http://placekitten.com/60/40" />
</div>
<script src="components/eventEmitter/EventEmitter.js"></script>
<script src="components/eventie/eventie.js"></script>
<script src="components/get-style-property/get-style-property.js"></script>
<script src="components/classie/classie.js"></script>
<script src="components/get-size/get-size.js"></script>
<script src="draggabilly.js"></script>
<script>
window.onload = function() {
var ex1 = document.getElementById('ex1');
var drag1 = new Draggabilly( ex1 );
var ex2 = document.getElementById('ex2');
var drag2 = new Draggabilly( ex2 );
drag2.on( 'dragStart', function( instance, event, pointer ) {
console.log('dragStart', instance.position.x, instance.position.y, event.type, pointer.pageX, pointer.pageY );
});
drag2.on( 'dragMove', function( instance, event, pointer ) {
console.log('dragMove', instance.position.x, instance.position.y, event.type, pointer.pageX, pointer.pageY );
});
drag2.on( 'dragEnd', function( instance, event, pointer ) {
console.log( 'dragEnd', instance.position.x, instance.position.y, event && event.type, pointer && pointer.pageX, pointer && pointer.pageY );
});
var handleDraggie = new Draggabilly( document.querySelector('#has-handles'), {
handle: '.handle'
});
var container1Draggers = [];
var dragger;
var elems = document.querySelectorAll('#container1 .box');
function handleDraggerEvent( instance, event, pointer ) {
console.log( event.type, instance.position.x, instance.position.y );
}
for ( var i=0, len = elems.length; i < len; i++ ) {
dragger = new Draggabilly( elems[i], {
containment: true
});
dragger.on( 'dragStart', handleDraggerEvent );
dragger.on( 'dragEnd', handleDraggerEvent );
}
// toggle drag2 enable/disable on [B] keypress
eventie.bind( document, 'keyup', function( event ) {
var code = event.keyCode || event.which;
// console.log( code );
switch ( code ) {
case 66 : // B
drag2[ drag2.isEnabled ? 'disable' : 'enable' ]();
break;
}
});
( function() {
var elem = document.querySelector('#kitten');
new Draggabilly( elem );
})();
( function() {
var elem = document.querySelector('#kitties');
new Draggabilly( elem );
})();
};
</script>
</body>
</html>