178 lines
4.9 KiB
HTML
178 lines
4.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Semantic Zoom</title>
|
|
<style>
|
|
html {
|
|
height: 100%;
|
|
--spring-easing: linear(
|
|
0,
|
|
0.009,
|
|
0.035 2.1%,
|
|
0.141,
|
|
0.281 6.7%,
|
|
0.723 12.9%,
|
|
0.938 16.7%,
|
|
1.017,
|
|
1.077,
|
|
1.121,
|
|
1.149 24.3%,
|
|
1.159,
|
|
1.163,
|
|
1.161,
|
|
1.154 29.9%,
|
|
1.129 32.8%,
|
|
1.051 39.6%,
|
|
1.017 43.1%,
|
|
0.991,
|
|
0.977 51%,
|
|
0.974 53.8%,
|
|
0.975 57.1%,
|
|
0.997 69.8%,
|
|
1.003 76.9%,
|
|
1.004 83.8%,
|
|
1
|
|
);
|
|
--spring-duration: 0.4s;
|
|
}
|
|
|
|
body {
|
|
font-family: monospace;
|
|
min-height: 100%;
|
|
position: relative;
|
|
margin: 0;
|
|
}
|
|
|
|
::view-transition-group(g0),
|
|
::view-transition-group(g1),
|
|
::view-transition-group(g2),
|
|
::view-transition-old(g0),
|
|
::view-transition-old(g1),
|
|
::view-transition-old(g2),
|
|
::view-transition-new(g0),
|
|
::view-transition-new(g1),
|
|
::view-transition-new(g2) {
|
|
animation-timing-function: var(--spring-easing);
|
|
animation-duration: var(--spring-duration);
|
|
}
|
|
|
|
::view-transition-old(*),
|
|
::view-transition-new(*) {
|
|
height: 100%;
|
|
}
|
|
|
|
::view-transition-group(slider),
|
|
::view-transition-old(slider),
|
|
::view-transition-new(slider) {
|
|
animation-duration: 0s !important;
|
|
}
|
|
|
|
label {
|
|
display: flex;
|
|
align-items: center;
|
|
margin: 1rem;
|
|
}
|
|
|
|
folk-shape {
|
|
background: black;
|
|
color: white;
|
|
max-width: 40ch;
|
|
padding: 0.5rem;
|
|
border-radius: 5px;
|
|
|
|
h2 {
|
|
margin: 0;
|
|
/* set the aspect ratio to be the same, needed for view transition */
|
|
width: fit-content;
|
|
}
|
|
|
|
p {
|
|
margin: 0;
|
|
}
|
|
}
|
|
|
|
body[zoom='0'] folk-shape {
|
|
width: 20px;
|
|
aspect-ratio: 1;
|
|
border-radius: 50%;
|
|
}
|
|
|
|
body[zoom='0'] folk-shape :is(h2, p),
|
|
body[zoom='50'] folk-shape p {
|
|
display: none;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body zoom="1">
|
|
<label>
|
|
Zoom:
|
|
<input type="range" min="0" max="100" value="100" style="view-transition-name: slider" />
|
|
</label>
|
|
|
|
<folk-shape id="box1" x="100" y="100">
|
|
<h2>Lorem ispum</h2>
|
|
<p>
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
|
|
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
|
|
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
|
|
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est
|
|
laborum.
|
|
</p>
|
|
</folk-shape>
|
|
|
|
<folk-shape id="box2" x="400" y="400">
|
|
<h2>Dolor sit amet</h2>
|
|
<p>
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
|
|
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
|
|
consequat.
|
|
</p>
|
|
</folk-shape>
|
|
|
|
<folk-shape id="box3" x="150" y="600">
|
|
<h2>Consectetur elit</h2>
|
|
<p>
|
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
|
|
magna aliqua.
|
|
</p>
|
|
</folk-shape>
|
|
|
|
<folk-arrow source="#box1" target="#box2"></folk-arrow>
|
|
<folk-arrow source="#box2" target="#box3"></folk-arrow>
|
|
<folk-arrow source="#box1" target="#box3"></folk-arrow>
|
|
|
|
<script type="module">
|
|
import '../lib/standalone/folk-shape.ts';
|
|
import '../lib/standalone/folk-arrow.ts';
|
|
|
|
document.body.querySelectorAll('folk-shape').forEach((el, i) => (el.style.viewTransitionName = `g${i}`));
|
|
document.body.querySelectorAll('folk-arrow').forEach((el, i) => (el.style.viewTransitionName = `c${i}`));
|
|
document.body.querySelectorAll('h2').forEach((el, i) => (el.style.viewTransitionName = `h${i}`));
|
|
document.body.querySelectorAll('p').forEach((el, i) => (el.style.viewTransitionName = `p${i}`));
|
|
|
|
const range = document.querySelector('input');
|
|
|
|
range.addEventListener('input', (e) => {
|
|
const currentZoom = range.valueAsNumber;
|
|
let semanticZoom;
|
|
|
|
if (currentZoom < 20) {
|
|
semanticZoom = 0;
|
|
} else if (currentZoom < 80) {
|
|
semanticZoom = 50;
|
|
} else {
|
|
semanticZoom = 1;
|
|
}
|
|
|
|
if (semanticZoom !== Number(document.body.getAttribute('zoom'))) {
|
|
document.startViewTransition(() => {
|
|
document.body.setAttribute('zoom', semanticZoom);
|
|
});
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|