-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
126 lines (105 loc) · 3.55 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
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width'>
<link rel='stylesheet' type='text/css' href='http://fonts.googleapis.com/css?family=Numans'>
<style>
body {
padding: 30px;
color: #444;
font-family: Arial, sans-serif;
}
#area {
height: 400px;
position: relative;
}
#area .drag {cursor:move; background: rgba(122, 122, 122, 0.8)}
#area > div {
background: rgba(122, 122, 122, 0.3);
position: absolute;
text-align: center;
font-size: 50px;
width: 60px;
height: 60px;
}
.over {
background: rgba(255, 0, 0, 0.5) !important;
}
.under {
background: rgba(0, 255, 0, 0.5) !important;
}
#box0 {
top: 0;
left: 0;
z-index: 1;
}
#box1 {
top: 260px;
left: 50px;
}
#box2 {
top: 110px;
left: 160px;
}
#box3 {
top: 200px;
left: 200px;
}
#box4 {
top: 50px;
left: 400px;
}
#state {height:80px}
</style>
<title>jquery.overlaps.js | Determine if an element overlaps/collides another.</title>
</head>
<body>
<div id="area">
<div class="drag" id="box0"></div>
<div class="drop" id="box1">1</div>
<div class="drop" id="box2">2</div>
<div class="drop" id="box3">3</div>
<div class="drop" id="box4">4</div>
</div>
<div id="state"></div>
<script src='http://code.jquery.com/jquery-1.9.1.min.js'></script>
<script src='jquery.overlaps.js'></script>
<script>
var box = '#box0',
drag = $('.drag'),
drop = $('.drop'),
state = $('#state');
drag.on('mousedown', function(e) {
var elem = $(this),
start = {
top: parseFloat(elem.css('marginTop').replace(/px/, '')),
left: parseFloat(elem.css('marginLeft').replace(/px/, ''))
},
mouse = {
top: e.clientY,
left: e.clientX
};
$(document).on('mousemove', function(e) {
var end = {
Y: start.top + e.clientY - mouse.top,
X: start.left + e.clientX - mouse.left
};
elem.css({
marginTop: end.Y + 'px',
marginLeft: end.X + 'px'
});
/*** :plugin specific code ***/
var collides = drop.overlaps(box);
$(box)[collides.hits.length ? 'addClass' : 'removeClass']('over');
drop.removeClass('under');
$(collides.targets).addClass('under');
/*** plugin specific code: ***/
}).on('mouseup', function() {
$(this).off('mousemove');
});
e.preventDefault();
});
</script>
</body>
</html>