Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/vtbag/website. The @vtbag website. ⭐️ Please star to support this work! ⭐️
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279---const SIZE = 12;---
<!doctype html><html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, minimum-scale=1.0" /> <title>Vector Demo | vtbag.dev</title> <link rel="canonical" href="https://vtbag.dev/vector-demo/" /> <link rel="icon" href="/bag4.png" type="image/png" /> <meta property="og:title" content="The Vector Demo" /> <meta property="og:url" content="https://vtbag.dev/vector-demo/" /> <meta property="og:locale" content="en" /> <meta property="og:description" content="A view transition tech demo were the old and new positions of morphing images control the trajectories." /><meta property="og:site_name" content="@vtbag" /><meta name="twitter:card" content="summary_large_image" /><meta name="description" content="A view transition tech demo were the old and new positions of morphing images control the trajectories." /><meta property="og:image" content="/vector-og.png" /> </head> <body> <h1>Click somewhere to<br />shuffle the blocks!</h1> <h2><a href="/tools/utensil-drawer/#morphing-vector">[Leave demo]</a></h2> <div class="container"> <div id="elements-grid"></div> </div> <main> <p> This tech demo showcases curved morph animations like those seen on <a href="https://events-3bg.pages.dev/jotter/styling/" target="_blank">the vtbot website</a >. </p> <p> The fun part: the shuffle is random, but the morphs derive their trajectories dynamically from the pseudo-elements' positions. Each one curves <a href="/tools/utensil-drawer/#morphing-vector" >based on the distance it needs to travel</a >. Longer distances result in higher arcs! </p> <p> Each direction has its own lane. It works in both portrait and landscape viewports. </p> <p> Bonus: new transitions are <a href="/tools/utensil-drawer/#maystartviewtransition" >chained and do not interrupt</a > ones already in progress. </p> </main> <section> <button>Toggle Code</button> <img id="code" class="hidden" src="/vector-code.png" alt="Code snippet" /> </section> </body></html>
<style set:text=`:root{--size: ${SIZE};}`></style>
<style is:global>
p { margin-bottom: 1ex; } .hidden { transform: scale(0);
} img { max-width: 80%; max-height: 80%; width: auto; height: auto; position: fixed; top: 2ex; left: 2ex; z-index: 1; transition: all 0.5s ease-in-out; } main { position: fixed; bottom: 2ex; right: 2ex; width: 35vw; transition: all 0.25s ease-in-out; }
section { position: fixed; bottom: 2em; left: 2em; transition: all 0.25s ease-in-out; } @media (orientation: landscape) { main { width: calc(100vw - 2ex); max-width: 666px; padding-left: 2ex; } section { bottom: calc(100vh - 3em); left: calc(100vw - 14ex); right: 2ex; } }
:root { color-scheme: light dark; view-transition-name: none; } * { margin: 0; padding: 0; box-sizing: border-box; }
body { height: 100vh; }
h1, h2 { font-size: 4vmin; padding: 2em; position: absolute; } h2 { font-size: 2vmin; } kbd { font-family: inherit; font-size: 0.875em; padding: 0.2em 0.4em; border: 1px solid light-dark(#999, #666); border-radius: 4px; background: light-dark(#f7f7f7, #333); box-shadow: inset 0 -2px 0 light-dark(#d1d1d1, #111); color: light-dark(#333, #f7f7f7); font-weight: 600; cursor: pointer; } .container { display: flex; height: 100%; justify-content: center; align-items: center; }
#elements-grid { display: grid; grid-template-columns: repeat(1, 1fr); height: 90%; gap: 10px; } .element { width: calc(66vmax / var(--size) - 10px); height: calc(66vmax / var(--size) - 10px); view-transition-class: el; transition: all 0.5s ease-in-out; }
.element:hover { transform: scale(1.1); } .circle { border-radius: 50%; }
.square { border-radius: 5px; }
/* This is it */ ::view-transition-group(*) { animation-duration: 1s; animation-timing-function: ease-in-out; }
:active-view-transition-type(with-vectors)::view-transition-image-pair(.el) { animation-name: arc; animation-timing-function: ease-in-out; } @keyframes arc { 50% { transform: translateX( calc(var(--vtbag-vector-to-y) / 3 - var(--vtbag-vector-from-y) / 3) ); } }
/* And some tweaks for horizontal mode */
@media (orientation: landscape) { #elements-grid { grid-template-columns: repeat(var(--size), 1fr); width: 90%; height: auto; gap: 10px; } @keyframes arc { 50% { transform: translateY( calc(var(--vtbag-vector-to-x) / 3 - var(--vtbag-vector-from-x) / 3) ); } } }</style>
<script is:inline set:text=`window.SIZE = ${SIZE}` /><script> import { mayStartViewTransition } from "@vtbag/utensil-drawer/may-start-view-transition"; import { setVectors } from "@vtbag/utensil-drawer/vectors";
// Color palettes for gradients const colorPalettes = [ ["#FF6B6B", "#4ECDC4"], ["#A8E6CF", "#FFD3B6"], ["#FFAAA5", "#FFD3B6"], ["#FF9A8B", "#FF6A88"], ["#4158D0", "#C850C0"], ["#0093E9", "#80D0C7"], ["#8EC5FC", "#E0C3FC"], ["#D9AFD9", "#97D9E1"], ];
function createElements() { const grid = document.getElementById("elements-grid")!; // @ts-ignore for (let i = 0; i < window.SIZE; i++) { const element = document.createElement("div"); element.className = `element ${Math.random() > 0.5 ? "circle" : "square"}`; element.style.viewTransitionName = `el-${i}`; const palette = colorPalettes[Math.floor(Math.random() * colorPalettes.length)]; element.style.background = `linear-gradient( ${Math.floor(Math.random() * 360)}deg, ${palette![0]}, ${palette![1]})`; grid.appendChild(element); } }
function shuffleElements() { const grid = document.getElementById("elements-grid")!; const random = [...grid.querySelectorAll(".element")].sort( () => Math.random() - 0.5 ); grid.innerHTML = ""; random.forEach((element) => grid.insertAdjacentElement("beforeend", element) ); }
document.addEventListener("DOMContentLoaded", () => { createElements(); addEventListener("click", async (e) => { if (e.defaultPrevented) return; const transition = mayStartViewTransition(shuffleElements, { collisionBehavior: "chaining", useTypesPolyfill: "auto", }); transition.ready.then(() => { setVectors([{ pattern: ".*", props: ["x", "y"] }], "pseudo"); transition.types.add("with-vectors"); }); }); document.querySelector("button")?.addEventListener("click", (e) => { e.preventDefault(); document.querySelector("img")?.classList.toggle("hidden"); }); });</script>