forked from archisvaze/liquid-glass
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedgeTest.html
More file actions
290 lines (246 loc) · 9.98 KB
/
edgeTest.html
File metadata and controls
290 lines (246 loc) · 9.98 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>Liquid Glass</title>
<script>
window.va = window.va || function () { (window.vaq = window.vaq || []).push(arguments); };
</script>
<script defer src="/_vercel/insights/script.js"></script>
<style>
:root {
/* Inner shadow */
--shadow-offset: 0;
--shadow-blur: 20px;
--shadow-spread: -5px;
--shadow-color: rgba(255, 255, 255, 0.7);
/* Painted glass */
--tint-color: 255, 255, 255;
--tint-opacity: 0.4;
/* Background frost */
--frost-blur: 2px;
/* SVG noise/distortion */
--noise-frequency: 0.008;
--distortion-strength: 77;
/* Outer shadow blur */
--outer-shadow-blur: 24px;
}
body {
margin: 0;
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background:
url('https://images.unsplash.com/photo-1618221195710-dd6b41faaea6?q=80&w=2000&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfDB8fGVufDB8fHx8fA%3D%3D') center/cover no-repeat;
font-family: sans-serif;
font-weight: 300;
position: relative;
max-width: 100vw;
max-height: 100vh;
overflow: hidden;
}
#controls {
position: fixed;
top: 10px;
left: 10px;
background: rgba(0, 0, 0, 0.6);
color: #fff;
padding: 12px;
border-radius: 8px;
font-size: 14px;
max-width: 280px;
max-height: 90vh;
overflow-y: auto;
}
#controls h2 {
margin: 8px 0 4px;
font-size: 16px;
}
#controls label {
display: flex;
justify-content: space-between;
align-items: center;
margin: 4px 0;
}
#controls input[type=range] {
width: 140px;
}
#controls input[type=color],
#controls input[type=text] {
border: none;
padding: 0;
width: 120px;
height: 24px;
background: #fff;
color: #000;
font-size: 12px;
}
.glassDiv {
position: absolute;
width: 300px;
height: 200px;
border-radius: 28px;
cursor: move;
isolation: isolate;
touch-action: none;
box-shadow: 0px 6px var(--outer-shadow-blur) rgba(0, 0, 0, 0.2);
/* No filter or mask here now */
}
.glassDiv::before {
content: '';
position: absolute;
inset: 0;
z-index: 0;
border-radius: 28px;
box-shadow: inset var(--shadow-offset) var(--shadow-offset) var(--shadow-blur) var(--shadow-spread) var(--shadow-color);
background-color: rgba(var(--tint-color), var(--tint-opacity));
}
.glassDiv::after {
content: '';
position: absolute;
inset: 0;
z-index: -1;
border-radius: 28px;
backdrop-filter: blur(var(--frost-blur));
filter: url(#glass-distortion);
mask: url(#edge-mask);
-webkit-mask: url(#edge-mask);
isolation: isolate;
}
@media (max-width: 600px) {
.glassDiv {
top: 30%;
width: 250px;
height: 120px;
}
#controls {
top: auto;
bottom: 0;
left: 0;
width: 100%;
max-width: 94%;
border-radius: 0;
}
#controls input[type=range],
#controls input[type=text] {
width: 100%;
}
}
</style>
</head>
<body>
<div id="controls">
<h2>Inner Shadow</h2>
<label>Color: <input type="color" id="shadow-color" value="#ffffff"
style="width: 30px; height: 30px; border-radius: 4px;" /></label>
<label>Blur: <input type="range" id="shadow-blur" min="0" max="20" value="20" />px</label>
<label>Spread: <input type="range" id="shadow-spread" min="-10" max="10" value="-5" />px</label>
<h2>Glass Tint</h2>
<label>Tint Color: <input type="color" id="tint-color" value="#ffffff"
style="width: 30px; height: 30px; border-radius: 4px;" /></label>
<label>Opacity: <input type="range" id="tint-opacity" min="0" max="100" value="4" />%</label>
<h2>Frost Blur</h2>
<label>Blur Radius: <input type="range" id="frost-blur" min="0" max="30" value="2" />px</label>
<h2>Noise Distortion</h2>
<label>Noise Freq: <input type="range" id="noise-frequency" min="0" max="0.02" step="0.001"
value="0.008" /></label>
<label>Strength: <input type="range" id="distortion-strength" min="0" max="200" value="77" /></label>
<!-- <h2>Outer Shadow</h2>
<label>Blur: <input type="range" id="outer-shadow-blur" min="0" max="50" value="10" />px</label> -->
<h2>Background Image</h2>
<label>URL: <input type="text" id="bg-url" placeholder="https://..." /></label>
</div>
<div class="glassDiv"></div>
<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0" style="position:absolute; overflow:hidden">
<defs>
<!-- Distortion Filter -->
<filter id="glass-distortion" x="0%" y="0%" width="100%" height="100%">
<feTurbulence type="fractalNoise" baseFrequency="0.008 0.008" numOctaves="2" seed="92" result="noise" />
<feGaussianBlur in="noise" stdDeviation="2" result="blurred" />
<feDisplacementMap in="SourceGraphic" in2="blurred" scale="77" xChannelSelector="R"
yChannelSelector="G" />
</filter>
<!-- Edge Mask with Rounded Corners -->
<mask id="edge-mask" maskUnits="userSpaceOnUse" x="0" y="0" width="300" height="200">
<!-- Outer white rectangle with round corners -->
<rect width="300" height="200" fill="white" rx="28" ry="28" />
<!-- Inner black cutout with matching round corners and 10px inset -->
<rect x="10" y="10" width="280" height="180" fill="black" rx="18" ry="18" />
</mask>
</defs>
</svg>
<script>
(function () {
const root = document.documentElement;
function setVar(name, val) { root.style.setProperty(name, val); }
function updateSVG() {
const freq = parseFloat(document.getElementById('noise-frequency').value);
const scale = document.getElementById('distortion-strength').value;
document.querySelector('feTurbulence').setAttribute('baseFrequency', `${freq} ${freq}`);
document.querySelector('feDisplacementMap').setAttribute('scale', scale);
}
function updateBackground() {
const url = document.getElementById('bg-url').value;
if (url) {
document.body.style.background = `url('${url}') center/cover no-repeat`;
}
}
const controls = {
'shadow-color': ['--shadow-color', v => v],
'shadow-blur': ['--shadow-blur', v => v + 'px'],
'shadow-spread': ['--shadow-spread', v => v + 'px'],
'tint-color': ['--tint-color', v => v.match(/\w\w/g).map(h => parseInt(h, 16)).join(',')],
'tint-opacity': ['--tint-opacity', v => v / 100],
'frost-blur': ['--frost-blur', v => v + 'px'],
// 'outer-shadow-blur': ['--outer-shadow-blur', v => v + 'px']
};
function updateAll() {
Object.entries(controls).forEach(([id, [cssVar, fn]]) => {
const el = document.getElementById(id);
if (el) setVar(cssVar, fn(el.value));
console.log(`id: ${id} | value:${el.value}`)
});
updateSVG();
updateBackground();
}
document.querySelectorAll('#controls input').forEach(i =>
i.addEventListener('input', updateAll)
);
updateAll();
})();
// ——— fully draggable in X and Y via Pointer Events ———
dragElement(document.querySelector('.glassDiv'));
function dragElement(elmnt) {
let startX = 0, startY = 0;
const onPointerDown = e => {
e.preventDefault();
const rect = elmnt.getBoundingClientRect();
elmnt.style.position = 'absolute';
elmnt.style.top = rect.top + 'px';
elmnt.style.left = rect.left + 'px';
elmnt.style.transform = 'none';
startX = e.clientX;
startY = e.clientY;
document.addEventListener('pointermove', onPointerMove);
document.addEventListener('pointerup', onPointerUp, { once: true });
};
const onPointerMove = e => {
e.preventDefault();
const dx = e.clientX - startX;
const dy = e.clientY - startY;
startX = e.clientX;
startY = e.clientY;
elmnt.style.left = (elmnt.offsetLeft + dx) + 'px';
elmnt.style.top = (elmnt.offsetTop + dy) + 'px';
};
const onPointerUp = () => {
document.removeEventListener('pointermove', onPointerMove);
};
elmnt.addEventListener('pointerdown', onPointerDown);
}
</script>
</body>
</html>