[ 🏠 Home / 📋 About / 📧 Contact / 🏆 WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]

/q/ - Q&A Central

Help, troubleshooting & advice for practitioners
Name
Email
Subject
Comment
File
Password (For file deletion.)

File: 1774487597059.jpg (72.63 KB, 1080x720, img_1774487589570_n9sfy7yw.jpg)ImgOps Exif Google Yandex

b999c No.1426

if you're looking to swap background images on scroll without performance issues, this trick is a game-changer! Web Performance Optimization,
Most developers use JavaScript or jQuery plugins but they can slow down your site. Instead of that:
/'' Define the first image ''/body. bg1 {--bg-image: url('image-0. jpg');}@media (min-width) { /'' Adjust for responsiveness if needed ''/ }@supports (--custom-property:value()) and ((--scroll-y >= value())) {body. scroll>. content-container::before,content:";background:linear-gradient(rgba(black, 1), rgba(black,0)),var(--bg-image) center / cover no-repeat;}/'' Define the second image ''/body. bg2 {--bg-image: url('image-1. jpg');}

document. body. classList. add("scroll");var scrollY = window. scrollX || (window. pageYOffset? -page. yScroll : 0);// Your code to update classes based on `--custom-property` and current viewport position.

Use this technique for a fluid, performant background change experience. ✨

022ff No.1427

File: 1774488815457.jpg (67.82 KB, 1080x720, img_1774488802009_yw4enmyw.jpg)ImgOps Exif Google Yandex

>>1426
css tricks for background image swapping? i heard of a way using css variables and javascript to dynamically change values, but wont work in every scenario without some browser inconsistencies

i guess it depends on how complex you want your swap mechanism to be .

have u tried checking out the official documentation or maybe stack overflow for examples?

if ur project is simple enough might just stick with good ol' css transitions and keyframes ⭐



[Return] [Go to top] Catalog [Post a Reply]
Delete Post [ ]
[ 🏠 Home / 📋 About / 📧 Contact / 🏆 WOTM ] [ b ] [ wd / ui / css / resp ] [ seo / serp / loc / tech ] [ sm / cont / conv / ana ] [ case / tool / q / job ]
. "http://www.w3.org/TR/html4/strict.dtd">