-
Notifications
You must be signed in to change notification settings - Fork 7
/
example.html
96 lines (88 loc) · 2.5 KB
/
example.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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>geometry.js example</title>
<style type="text/css">
* { margin: 0; padding: 0; border: 0; }
body {
background: #EFEFEF;
}
#info {
padding: 20px;
font-family: Helvetica, sans-serif;
font-size: 14px;
font-color: #3A3A3A;
}
.box {
position: absolute;
background: #0A4F1A;
cursor: move;
z-index: 42;
}
.box.intersects {
background: #238832;
}
.box.contains {
background: #25B035;
}
#box1 {
width: 130px;
height: 150px;
left: 20px;
top: 50px;
}
#box2 {
width: 90px;
height: 100px;
left: 40px;
top: 75px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/mootools/1.3.1/mootools.js" type="text/javascript" charset="utf-8"></script>
<script src="geometry.js" type="text/javascript" charset="utf-8"></script>
<script src="geometry-mootools.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
window.addEvent('domready', function() {
var box1 = document.id('box1');
var box2 = document.id('box2');
var info = document.id('info');
function hitTest(){
var rect1 = box1.getRect(), rect2 = box2.getRect();
box2.toggleClass('intersects', rect1.intersectsRect(rect2));
box2.toggleClass('contains', rect1.containsRect(rect2));
info.set('text', 'Distance between centers: ' + rect1.getMid().distanceTo(rect2.getMid()).round(2));
}
var dragEl, posOffset;
new Elements([box1, box2]).addEvent('mousedown', function(event){
event.stop();
dragEl = event.target;
posOffset = new Point(event.page).substractPoint(dragEl.getPosition());
});
document.addEvents({
'mouseup': function(event){
if (dragEl != null) {
event.stop();
dragEl = null;
}
},
'mousemove': function(event){
if (dragEl != null) {
event.stop();
var newPos = new Point(event.page).substractPoint(posOffset);
dragEl.setPosition(newPos);
hitTest();
}
}
});
hitTest();
});
</script>
</head>
<body>
<div id="info"></div>
<div class="box" id="box1"></div>
<div class="box" id="box2"></div>
</body>
</html>