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. ✨