Share Posted May 10, 2021 is it possible for scrollColorElems to use gradients? html <div id="section1" class="mymodeheader-newmods mytop"><img class="hero__image" data-scrollcolor="linear-gradient(90deg, #46224e 0%, #30184f 85%)" ) src="https://parkviewhomes.info/energy-star/banner-top-01.svg" alt="" /></div> window.addEventListener("load", function () { const scrollColorElems = document.querySelectorAll("[data-scrollcolor]"); scrollColorElems.forEach((colorSection, i) => { const prevColor = i === 0 ? "#1b1521" : scrollColorElems[i - 1].dataset.scrollcolor; ScrollTrigger.create({ trigger: colorSection, start: "top bottom", onEnter: () => gsap.to("body", { backgroundColor: colorSection.dataset.scrollcolor, overwrite: "auto" }), onLeaveBack: () => gsap.to("body", { backgroundColor: prevColor, overwrite: "auto" }) }); }); }); See the Pen PopPqPO by davicoo (@davicoo) on CodePen Link to comment Share on other sites More sharing options...
Share Posted May 10, 2021 Here's a forum post that should help you ☺️ Shout if we can help to clarify anything. 2 Link to comment Share on other sites More sharing options...
Author Share Posted May 10, 2021 I'm not sure that helps but good to know. ...I still can't tell if gradients with data-scrollcolor think I have here ? data-scrollcolor="linear-gradient(90deg, #46224e 0%, #30184f 85%)" ) gsap.registerPlugin(ScrollTrigger); window.addEventListener("load", function () { const scrollColorElems = document.querySelectorAll("[data-scrollcolor]"); scrollColorElems.forEach((colorSection, i) => { const prevColor = i === 0 ? "linear-gradient(90deg, #46224e 0%, #30184f 85%)"" : scrollColorElems[i - 1].dataset.scrollcolor; ScrollTrigger.create({ trigger: colorSection, start: "top bottom", onEnter: () => gsap.to("body", { backgroundColor: colorSection.dataset.scrollcolor, overwrite: "auto" }), onLeaveBack: () => gsap.to("body", { backgroundColor: prevColor, overwrite: "auto" }) }); }); }); Link to comment Share on other sites More sharing options...
Share Posted May 10, 2021 What did you try? 1 hour ago, Dcoo said: So you can't use gradients with ScrollTrigger / data-scrollcolor ? Get a tween working first. Add in the more complicated stuff later. 1 Link to comment Share on other sites More sharing options...
Share Posted May 10, 2021 Ah, yeah. I assumed there was a bug causing an issue. This is actually *mega cool* I had no idea GSAP could animate gradients this simply. In my head they were a binary background property that couldn't be animated and I assumed we'd need some extra assistance with them BUT look, it's just animating like pure magic! Here - very simplified pen to show you (this is what we mean when we ask for a reduced test case.) Simplified code makes it a lot easier to work out what's going on. See the Pen a565a64ed971eadafd29a4c932ae9d05?editors=1010 by cassie-codes (@cassie-codes) on CodePen 5 Link to comment Share on other sites More sharing options...
Share Posted May 10, 2021 😍 so beautiful. Gosh GSAP is just THE BEST. Learn a new thing every day. 3 Link to comment Share on other sites More sharing options...
Share Posted May 10, 2021 I just had to go back and try animating with CSS for my sanity and I'm not going mad. This is indeed magic. See the Pen 20d1099a0e2bcda17c41c7e2e4561edc by cassie-codes (@cassie-codes) on CodePen 3 Link to comment Share on other sites More sharing options...
Author Share Posted May 10, 2021 when I use a hex it works great, I was just wondering is it could do gradients as well I tried this but it failed badly :) gsap.registerPlugin(ScrollTrigger); window.addEventListener("load", function () { const scrollColorElems = document.querySelectorAll("[data-scrollcolor]"); scrollColorElems.forEach((colorSection, i) => { const prevColor = i === 0 ? "linear-gradient(180deg, #FBD786 0%, #f7797d 85%)" : scrollColorElems[i - 1].dataset.scrollcolor; ScrollTrigger.create({ trigger: colorSection, start: "top bottom", onEnter: () => gsap.to("body", { backgroundColor: colorSection.dataset.scrollcolor, overwrite: "auto" }), onLeaveBack: () => gsap.to("body", { background-image: prevColor, overwrite: "auto" }) }); }); }); Link to comment Share on other sites More sharing options...
Author Share Posted May 10, 2021 1 hour ago, OSUblake said: What did you try? Get a tween working first. Add in the more complicated stuff later. Using a hex color it works great, I'm just not sure if using gradients is possible Link to comment Share on other sites More sharing options...
Share Posted May 10, 2021 @Cassie just posted a demo. See the Pen a565a64ed971eadafd29a4c932ae9d05 by cassie-codes (@cassie-codes) on CodePen The other thread she linked also shows different ways to animate gradients. 2 Link to comment Share on other sites More sharing options...
Author Share Posted May 10, 2021 3 hours ago, Cassie said: Here's a forum post that should help you ☺️ Shout if we can help to clarify anything. Thank you for the reply, and i'm sorry if I came off rude. have a great day Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now