/
index.html
86 lines (74 loc) · 2.2 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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.4.1/build/cssreset/cssreset.css" />
<style type="text/css">
p { padding-top: 10px; padding-bottom: 10px; clear: both; }
li { height: 40px; width: 40px; float: left; margin-right: 3px; margin-bottom: 3px; border: solid 3px #666; border-radius: 10px; }
.dragables li { background: #ccc; cursor: pointer; }
.droppables li { background: #666; }
</style>
</head>
<body>
<p>Dragables</p>
<ul class="dragables">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<p>Droppables</p>
<ul class="droppables">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</body>
<script type="text/javascript">
if('__proto__' in {}){
// zepto
document.write('<script type="text/javascript" src="zepto/zepto.js"></script><script type="text/javascript" src="zepto/event.js"></script>');
} else {
// jquery
document.write('<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>');
}
</script>
<script type="text/javascript" src="zepto/event.js"></script>
<script type="text/javascript" src="lib/event.js"></script>
<script type="text/javascript" src="lib/rect.js"></script>
<script type="text/javascript" src="lib/drag-and-drop.js"></script>
<script type="text/javascript">
$(function(){
// set dragables
$('.dragables li').each(function(){
drag.set(this, {
start: function(){
// add actions here to fire when drag starts
},
move: function(hits){
var di = drop.items();
for(var i = 0; i < di.length; i++) $(di[i]).attr('style', '');
if(hits.length) {
$(hits).css('background', '#f90');
$(rect.closest(hits, this)).css('background', 'red');
}
},
drop: function(hits){
if(hits.length) {
// snap dragable to droppable
rect.snap(this, rect.closest(hits, this));
} else {
// or return to original position
drag.reset(this);
}
}
});
});
// set dropables
$('.droppables li').each(function(){
drop.set(this);
});
});
</script>
</html>