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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111---import Demo from "@/layouts/DemoLayout.astro";---
<Demo title="View Transition Example: Different Images & Aspect Ratios" backlink="/basics/examples/#basicim2" prev="/demo/BasicIM/" next="/demo/BasicIM3/" description="Basic morph transition between two different images of different aspect ratio" image="/bag-og.png"> <p> This example demonstrates the default morph transition between two images, with the key difference being that these images have different aspect ratios compared to the <a href="/demo/BasicIM/">previous example</a>. </p>
<div id="DOM1" class="active"> <div class="card"> <img src="/portrait.webp" /> <div> <h4>Teaser Heading</h4> <p>This is a teaser text for the card. (Click to start)</p> </div> </div> <div style="height: 3.5em"></div> </div> <div id="DOM2"> <article> <div> <h3>Details</h3> <p> Some text that describes the details of what the card teases in more detail. Click [here] to return to teaser view. </p> </div> <img src="/landscape.webp" /> </article> </div> <style is:global> #DOM1, #DOM2 { display: none; cursor: pointer; } #DOM1.active, #DOM2.active { display: block; } </style> <style is:inline slot="late-head"> ::view-transition-group(*) { animation-duration: 1s; } .card img, article img { view-transition-name: img; }
#DOM1 { margin: auto; width: max(50%, 300px); } .card { display: flex; border: 2px solid gray; border-radius: 6px; } .card img { width: 30%; } .card div { padding: 1rem; } article { max-width: 100%; display: flex; flex-wrap: wrap; } article div { padding: 1rem; max-width: 40%; } article img { margin: auto; width: min(400px, 50vw); border-radius: 8px; box-shadow: 0 2px 2px rgba(0, 0, 0, 0.5); } </style> <script> document.querySelectorAll("#DOM1, #DOM2").forEach((elem) => elem.addEventListener("click", () => { mayViewTransition(() => { elem.classList.remove("active"); elem .parentElement!.querySelector( elem.id === "DOM1" ? "#DOM2" : "#DOM1" ) ?.classList.add("active"); }); }) ); function mayViewTransition(fun: () => void) { // @ts-ignore document.startViewTransition ? document.startViewTransition(fun) : fun(); } </script></Demo>