-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultiSquare.html
66 lines (63 loc) · 1.92 KB
/
multiSquare.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body {
margin: 0;
padding: 0;
}
svg {
top:0;
left:0;
height:100%;
width:100%;
position:fixed;
}
</style>
</head>
<body>
<svg></svg>
<script>
class Box {
constructor() {
this._color = '#' + Math.floor(Math.random() * 16777215).toString(16);
this._x = Math.floor(Math.random() * 600);
this._y = Math.floor(Math.random() * 400);
this._width = 100 + Math.floor(Math.random() * 500);
this._height = 100 + Math.floor(Math.random() * 300);
}
}
class Boxset {
constructor() {
this._box = [];
let random = Math.floor(Math.random() * 10) + 1;
for (let i = 0; i < random; i++) {
this._box.push(new Box());
}
}
getHtml() {
let html = '';
for (let i = 0; i < this._box.length; i++) {
html += `
<rect onclick="boxes.removeBox(${i})" width="${this._box[i]._width}" height="${this._box[i]._height}" x="${this._box[i]._x}"
y="${this._box[i]._y}" style="fill:${this._box[i]._color};stroke-width:3;stroke:rgb(0,0,0)" />
`;
}
return html;
}
show() {
document.querySelector('svg').innerHTML = boxes.getHtml();
}
removeBox(i) {
this._box.splice(i, 1);
boxes.show();
}
}
let boxes = new Boxset();
boxes.show();
</script>
</body>
</html>