forked from gridstack/gridstack.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
responsive.html
69 lines (63 loc) · 1.82 KB
/
responsive.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Responsive grid demo</title>
<link rel="stylesheet" href="demo.css"/>
<link rel="stylesheet" href="../dist/gridstack-extra.css"/>
<script src="../src/jquery.js"></script>
<script src="../src/gridstack.js"></script>
<script src="../src/jquery-ui.js"></script>
<script src="../src/gridstack.jQueryUI.js"></script>
</head>
<body>
<div>
<h1>Responsive grid demo</h1>
<div>
<span>Number of Columns:</span> <span id="column-text"></span>
</div>
<br/>
<div class="grid-stack">
</div>
</div>
<script type="text/javascript">
var grid = GridStack.init({
disableOneColumnMode: true, // will manually do 1 column
float: true });
var text = document.querySelector('#column-text');
function resizeGrid() {
var width = document.body.clientWidth;
if (width < 700) {
grid.column(1);
text.innerHTML = 1;
} else if (width < 850) {
grid.column(3);
text.innerHTML = 3;
} else if (width < 950) {
grid.column(6);
text.innerHTML = 6;
} else if (width < 1100) {
grid.column(8);
text.innerHTML = 8;
} else {
grid.column(12);
text.innerHTML = 12;
}
};
var items = [
{x: 0, y: 0, width: 2, height: 2},
{x: 2, y: 0, width: 2, height: 1},
{x: 5, y: 0, width: 1, height: 1},
{x: 1, y: 3, width: 4, height: 1},
{x: 5, y: 2, width: 2, height: 1},
{x: 0, y: 4, width: 12, height: 1}
];
grid.batchUpdate();
items.forEach(function(node, index) {
grid.addWidget('<div><div class="grid-stack-item-content">' + index + '</div></div>', node);
});
grid.commit();
resizeGrid();
window.addEventListener('resize', function() {resizeGrid()});
</script>
</body>
</html>