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.
1234567891011121314151617181920---layout: "@/layouts/ExplainerLayout.astro"demoTitle: "View Transition Example: Same Image, changing Aspect Ratio"demoText: "An optimized morph transition between different sections of the same image with different aspect ratios."title: "How does it work?"---
This example takes a rather unconventional approach. Instead of tweaking the old and new images until everything looks nice, it ignores them and sets a background image on the image pair pseudo element.```diff lang="css" ::view-transition-image-pair(img) { background-image: url("/landscape.webp"); background-position: center; background-size: cover; } ::view-transition-old(img), ::view-transition-new(img) { display: none; }```Be aware that this approach only works if the old and the new images have the same `object-position`, which has to be mirrored by the corresponding `background-position` property of the image pair pseudo element.