-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathtransform.html
122 lines (106 loc) · 3.56 KB
/
transform.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Transform Parent demo</title>
<link rel="stylesheet" href="demo.css"/>
<script src="../dist/gridstack-all.js"></script>
</head>
<body>
<div class="container-fluid">
<h1>Transform Parent demo</h1>
<p>example where the grid parent has a translate(50px, 100px) and a scale(<span id="scale-x"></span>, <span id="scale-y"></span>)</p>
<div>
<a class="btn btn-primary" onClick="addNewWidget()" href="#">Add Widget</a>
<a class="btn btn-primary" onClick="zoomIn()" href="#">Zoom in</a>
<a class="btn btn-primary" onClick="zoomOut()" href="#">Zoom out</a>
<a class="btn btn-primary" onClick="increaseScaleX()" href="#">Increase Scale X</a>
<a class="btn btn-primary" onClick="decreaseScaleX()" href="#">Decrease Scale X</a>
<a class="btn btn-primary" onClick="increaseScaleY()" href="#">Increase Scale Y</a>
<a class="btn btn-primary" onClick="decreaseScaleY()" href="#">Decrease Scale Y</a>
</div>
<br><br>
<div style="transform: translate(50px, 100px) scale(var(--global-scale-x), var(--global-scale-y)); transform-origin: 0 0;">
<div class="grid-stack"></div>
</div>
</div>
<script src="events.js"></script>
<script type="text/javascript">
let scaleX = 0.5;
let scaleY = 0.5;
let grid = GridStack.init({float: true});
addEvents(grid);
let items = [
{x: 0, y: 0, w: 2, h: 2},
{x: 2, y: 0, w: 1},
{x: 3, y: 0, h: 1},
{x: 0, y: 2, w: 2},
];
let count = 0;
getNode = function() {
let n = items[count] || {
x: Math.round(12 * Math.random()),
y: Math.round(5 * Math.random()),
w: Math.round(1 + 3 * Math.random()),
h: Math.round(1 + 3 * Math.random())
};
n.content = n.content || String(count);
count++;
return n;
};
addNewWidget = function() {
let w = grid.addWidget(getNode());
};
const updateScaleCssVariable = () => {
document.body.style.setProperty('--global-scale-x', `${scaleX}`);
document.body.style.setProperty('--global-scale-y', `${scaleY}`);
document.getElementById("scale-x").textContent = scaleX.toFixed(2);
document.getElementById("scale-y").textContent = scaleY.toFixed(2);
}
zoomIn = function() {
const scaleStep = scaleX < 1 ? 0.05 : 0.1;
scaleX += scaleStep;
scaleY += scaleStep;
updateScaleCssVariable();
}
zoomOut = function() {
if(scaleX >= 0.2 && scaleY >= 0.2) {
const scaleStep = scaleX < 1 ? 0.05 : 0.1;
scaleX -= scaleStep;
scaleY -= scaleStep;
updateScaleCssVariable();
}
}
increaseScaleX = function() {
const scaleStep = scaleX < 1 ? 0.05 : 0.1;
scaleX += scaleStep;
updateScaleCssVariable();
}
decreaseScaleX = function() {
if(scaleX >= 0.2) {
const scaleStep = scaleX < 1 ? 0.05 : 0.1;
scaleX -= scaleStep;
updateScaleCssVariable();
}
}
increaseScaleY = function() {
const scaleStep = scaleX < 1 ? 0.05 : 0.1;
scaleY += scaleStep;
updateScaleCssVariable();
}
decreaseScaleY = function() {
if(scaleY >= 0.2) {
const scaleStep = scaleX < 1 ? 0.05 : 0.1;
scaleY -= scaleStep;
updateScaleCssVariable();
}
}
updateScaleCssVariable();
addNewWidget();
addNewWidget();
addNewWidget();
</script>
</body>
</html>