-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo.html
91 lines (81 loc) · 2.55 KB
/
demo.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
<html>
<head>
<title>subdiv.js demo</title>
<style type="text/css">
body {
margin: 0;
padding: 0;
background: #000;
}
#viewport {
margin: 0 auto;
width: 500px;
height: 500px;
background: teal;
}
#container {}
#container div {
display: table;
background: #fff;
}
#container span {
display: table-cell;
text-align: center;
vertical-align: middle;
font: bold 50px 'Helvetica Neue', Helvetica, sans-serif;
color: #cacaca;
outline: 1px solid #f0f0f0;
}
#buttons {
position: absolute;
top: 10px;
right: 10px;
}
</style>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script type="text/javascript" src="subdiv.js"></script>
</head>
<body>
<div id="container">
<div><span>1</span></div>
<div><span>2</span></div>
<div><span>3</span></div>
<div><span>4</span></div>
<div><span>5</span></div>
<div><span>6</span></div>
<div><span>7</span></div>
<div><span>8</span></div>
<div><span>9</span></div>
<div><span>10</span></div>
<div><span>11</span></div>
<div><span>12</span></div>
<div><span>13</span></div>
<div><span>14</span></div>
<div><span>15</span></div>
<div><span>16</span></div>
<div><span>17</span></div>
</div>
<div id="buttons">
<button id="add">add</button>
<button id="remove_last">remove last</button>
<button id="remove_random">remove random</button>
</div>
<script type="text/javascript">
$(function(){
var subdiv = $('#container').subdiv();
$('#add').on('click', function(){
$('#container').append($('<div/>').append($('<span/>').text(subdiv.divs().length + 1)));
subdiv.resize();
});
$('#remove_last').on('click', function(){
$('#container div:last-child').remove();
subdiv.resize();
});
$('#remove_random').on('click', function(){
$('#container div').eq(Math.floor(Math.random() * subdiv.divs().length)).remove();
subdiv.resize();
});
});
</script>
</body>
</html>