-
Notifications
You must be signed in to change notification settings - Fork 831
Expand file tree
/
Copy pathoptical-sizing.html
More file actions
290 lines (265 loc) · 7.68 KB
/
optical-sizing.html
File metadata and controls
290 lines (265 loc) · 7.68 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>
<head>
<meta charset="utf-8">
<title>Variable Font example - optical sizing</title>
<style>
@font-face {
font-family: 'Amstelvar VF';
src: url('fonts/AmstelvarAlpha-VF.woff2') format('woff2-variations');
font-weight: 300 900;
font-stretch: 75% 150%;
font-style: normal;
font-display: swap;
}
html {
box-sizing: border-box;
font-size: 100%;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
body {
font: 1.2em "Amstelvar VF", Georgia, serif;
margin: 20px;
padding: 0;
}
.wrapper {
width: 100%;
display: grid;
grid-template-columns: 1fr;
grid-gap: 1rem;
}
@media screen and (min-width: 50rem) {
.wrapper {
grid-template-columns: 1fr 1fr;
}
}
textarea {
font-family: monospace;
display: block;
margin-bottom: 10px;
height: 160px;
background-color: #F4F7F8;
border: none;
border-left: 6px solid #558ABB;
color: #4D4E53;
padding: 1rem 0;
width: 100%;
}
textarea:nth-of-type(1) {
height: 130px;
}
textarea:nth-of-type(2) {
height: 100px;
}
.playable-buttons {
text-align: right;
width: 100%;
padding: 0.5rem 0;
font-size: 100%;
}
.section {
width: 100%;
border: 1px solid #4D4E53;
border-radius: 2px;
padding: 10px 14px 10px 10px;
margin-bottom: 10px;
}
.section input {
display: block;
margin: 5px;
}
.container * {
margin: 1.5rem 0;
}
.demo3 {
--text-axis: 64;
}
</style>
<style class="editable0">
/* font-optical-sizing can be auto or none */
.container0 * {
font-size: 64px;
font-optical-sizing: none;
}
</style>
<style class="editable1">
/* font-optical-sizing can be auto or none */
.container1 * {
font-size: 64px;
font-optical-sizing: auto;
}
</style>
<style class="editable2">
/* optical range is from 8 to 144 */
.container2 * {
font-size: 64px;
font-variation-settings: 'opsz' 64;
}
</style>
<style class="editable3">
/* Adjust with slider & custom property */
.container3 * {
font-size: 64px;
font-variation-settings: 'opsz' var(--text-axis);
}
</style>
</head>
<body>
<div class="wrapper">
<div class="demo0">
<section class="section section0">
<div class="container container0">
<p>Optical Size</p>
</div>
</section>
<textarea class="playable-css0">
/* font-optical-sizing can be auto or none */
.container0 * {
font-size: 64px;
font-optical-sizing: none;
}
</textarea>
<textarea id="code1" class="playable-html0">
<div class="container container0">
<p>Optical Size</p>
</div>
</textarea>
</div>
<div class="demo1">
<section class="section section1">
<div class="container container1">
<p>Optical Size</p>
</div>
</section>
<textarea class="playable-css1">
/* font-optical-sizing can be auto or none */
.container1 * {
font-size: 64px;
font-optical-sizing: auto;
}
</textarea>
<textarea id="code1" class="playable-html1">
<div class="container container1">
<p>Optical Size</p>
</div>
</textarea>
</div>
<div class="demo2">
<section class="section section2">
<div class="container container2">
<p>Optical Size</p>
</div>
</section>
<textarea class="playable-css2">
/* optical size range is from 8 to 144 */
.container2 * {
font-size: 64px;
font-variation-settings: 'opsz' 64;
}
</textarea>
<textarea id="code2" class="playable-html2">
<div class="container container2">
<p>Optical Size</p>
</div>
</textarea>
</div>
<div class="demo3">
<section class="section section3">
<div class="container container3">
<p>Optical Size</p>
</div>
</section>
<textarea class="playable-css3">
/* Adjust with slider & custom property */
.container3 * {
font-size: 64px;
font-variation-settings: 'opsz' var(--text-axis);
}
</textarea>
<textarea id="code3" class="playable-html3">
<div class="container container3">
<p>Optical Size</p>
</div>
</textarea>
<div class="controls range-slider">
<label for="controls__slider">Adjust Optical Sizing: </label><input type="range" name="range-slider" value="64" id="text-axis" class="controls--slider" min="8" max="144">
</div>
</div>
</div>
<div class="playable-buttons">
<input id="reset" type="button" value="Reset">
</div>
</body>
<script>
var section0 = document.querySelector('.section0');
var editable0 = document.querySelector('.editable0');
var textareaHTML0 = document.querySelector('.playable-html0');
var textareaCSS0 = document.querySelector('.playable-css0');
var section1 = document.querySelector('.section1');
var editable1 = document.querySelector('.editable1');
var textareaHTML1 = document.querySelector('.playable-html1');
var textareaCSS1 = document.querySelector('.playable-css1');
var section2 = document.querySelector('.section2');
var editable2 = document.querySelector('.editable2');
var textareaHTML2 = document.querySelector('.playable-html2');
var textareaCSS2 = document.querySelector('.playable-css2');
var section3 = document.querySelector('.section3');
var editable3 = document.querySelector('.editable3');
var textareaHTML3 = document.querySelector('.playable-html3');
var textareaCSS3 = document.querySelector('.playable-css3');
var rangeinput = document.querySelector('.controls--slider');
var reset = document.getElementById('reset');
var htmlCode0 = textareaHTML0.value;
var cssCode0 = textareaCSS0.value;
var htmlCode1 = textareaHTML1.value;
var cssCode1 = textareaCSS1.value;
var htmlCode2 = textareaHTML2.value;
var cssCode2 = textareaCSS2.value;
var htmlCode3 = textareaHTML3.value;
var cssCode3 = textareaCSS3.value;
function fillCode() {
editable0.innerHTML = textareaCSS0.value;
section0.innerHTML = textareaHTML0.value;
editable1.innerHTML = textareaCSS1.value;
section1.innerHTML = textareaHTML1.value;
editable2.innerHTML = textareaCSS2.value;
section2.innerHTML = textareaHTML2.value;
editable3.innerHTML = textareaCSS3.value;
section3.innerHTML = textareaHTML3.value;
rangeinput.value = 64;
document.querySelector('.demo3').style.setProperty('--text-axis', 64);
}
reset.addEventListener('click', function () {
textareaHTML0.value = htmlCode0;
textareaCSS0.value = cssCode0;
textareaHTML1.value = htmlCode1;
textareaCSS1.value = cssCode1;
textareaHTML2.value = htmlCode2;
textareaCSS2.value = cssCode2;
textareaHTML3.value = htmlCode3;
textareaCSS3.value = cssCode3;
fillCode();
});
textareaHTML0.addEventListener('input', fillCode);
textareaCSS0.addEventListener('input', fillCode);
textareaHTML1.addEventListener('input', fillCode);
textareaCSS1.addEventListener('input', fillCode);
textareaHTML2.addEventListener('input', fillCode);
textareaCSS2.addEventListener('input', fillCode);
textareaHTML3.addEventListener('input', fillCode);
textareaCSS3.addEventListener('input', fillCode);
window.addEventListener('load', fillCode);
// get the inputs
const inputs = [].slice.call(document.querySelectorAll('.demo3 .controls input'));
// listen for changes
inputs.forEach(input => input.addEventListener('change', handleUpdate));
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
function handleUpdate(e) {
document.querySelector('.demo3').style.setProperty(`--${this.id}`, this.value);
}
</script>
</html>