-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
103 lines (83 loc) · 3.16 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
<script>
var popups = [],
pumpPopup,
last = {},
hoseLeft, hoseRight,
lastHeight;
function launch() {
var i, popup,
width, height,
left, top;
width = 300;
height = 300;
for (i = 0; i < 3; i ++) {
left = Math.random()*(screen.width-width);
top = Math.random()*(screen.height-height);
popup = window.open('popup.html', 'popup'+i, 'width='+width+',height='+height+',left='+left+',top='+top)
popups.push(popup);
}
width = 300;
height = 500;
left = (screen.width-width)/2;
top = (screen.height-height)/2;
pumpPopup = window.open('pump.html', 'pump', 'width='+width+',height='+height+',left='+left+',top='+top)
}
function close() {
popups.forEach(function (popup) {
popup.close();
});
if (pumpPopup) pumpPopup.close();
}
function loop() {
var ppWidth, ppHeight, ppLeft, ppTop,
lPoint, rPoint,
testPoints,
leftCollision = false,
rightCollision = false,
height;
if (pumpPopup && pumpPopup.hoseLeft && pumpPopup.hoseRight) {
selected = [];
ppWidth = pumpPopup.outerWidth;
ppHeight = pumpPopup.outerHeight;
ppLeft = pumpPopup.screenLeft;
ppTop = pumpPopup.screenTop;
lPoint = [ppLeft, ppTop+ppHeight-100];
rPoint = [ppLeft+ppWidth, ppTop+ppHeight-100];
popups.forEach(function (popup) {
var pTop = popup.screenTop,
pLeft = popup.screenLeft,
pBottom = pTop + popup.outerHeight,
pRight = pLeft + popup.outerWidth;
if (lPoint[0] > pLeft && lPoint[0] < pRight && lPoint[1] > pTop && lPoint[1] < pBottom) {
if (selected.indexOf(popup) == -1) {
selected.push(popup);
leftCollision = true;
}
}
if (rPoint[0] > pLeft && rPoint[0] < pRight && rPoint[1] > pTop && rPoint[1] < pBottom) {
if (selected.indexOf(popup) == -1) {
selected.push(popup);
rightCollision = true;
}
}
});
pumpPopup.hoseLeft.className = leftCollision ? 'hose open' : 'hose';
pumpPopup.hoseRight.className = rightCollision ? 'hose open' : 'hose';
height = pumpPopup.outerHeight;
if (height < lastHeight) {
selected.forEach(function (popup) {
popup.pump((lastHeight - height) / 4);
});
}
lastHeight = height;
}
setTimeout(loop, 1000/10);
}
window.addEventListener('load', function () {
document.getElementById('launch-button').addEventListener('click', launch);
document.getElementById('close-button').addEventListener('click', close);
loop();
});
</script>
<button id="launch-button">launch</button>
<button id="close-button">close</button>