|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| 6 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 7 | + <title>CSS & attributes demo</title> |
| 8 | + |
| 9 | + <link rel="stylesheet" href="demo.css"/> |
| 10 | + <script src="../dist/gridstack-all.js"></script> |
| 11 | + |
| 12 | +</head> |
| 13 | +<body> |
| 14 | + <div class="container-fluid"> |
| 15 | + <h1>Demo showcasing how to use gridstack.js attributes in CSS</h1> |
| 16 | + <p>The center of the widget shows its dimensions by purely using CSS, no JavaScript involved.</p> |
| 17 | + <div> |
| 18 | + <a class="btn btn-primary" onClick="addNewWidget()" href="#">Add Widget</a> |
| 19 | + </div> |
| 20 | + <br><br> |
| 21 | + <div class="grid-stack show-dimensions"></div> |
| 22 | + </div> |
| 23 | + <script src="events.js"></script> |
| 24 | + <script type="text/javascript"> |
| 25 | + let grid = GridStack.init({ |
| 26 | + float: true, |
| 27 | + resizable: { handles: 'all'} |
| 28 | + }); |
| 29 | + addEvents(grid); |
| 30 | + |
| 31 | + let items = [ |
| 32 | + {x: 1, y: 1}, |
| 33 | + {x: 2, y: 2, w: 3}, |
| 34 | + {x: 4, y: 2}, |
| 35 | + {x: 3, y: 1, h: 2}, |
| 36 | + {x: 0, y: 6, w: 2, h: 2} |
| 37 | + ]; |
| 38 | + let count = 0; |
| 39 | + |
| 40 | + getNode = function() { |
| 41 | + let n = items[count] || { |
| 42 | + x: Math.round(12 * Math.random()), |
| 43 | + y: Math.round(5 * Math.random()), |
| 44 | + w: Math.round(1 + 3 * Math.random()), |
| 45 | + h: Math.round(1 + 3 * Math.random()) |
| 46 | + }; |
| 47 | + n.content = n.content || String(count); |
| 48 | + count++; |
| 49 | + return n; |
| 50 | + }; |
| 51 | + |
| 52 | + addNewWidget = function() { |
| 53 | + grid.addWidget(getNode()); |
| 54 | + }; |
| 55 | + |
| 56 | + addNewWidget(); |
| 57 | + </script> |
| 58 | +</body> |
| 59 | +</html> |
0 commit comments