smat-ctrl Posted April 15 Share Posted April 15 I'm wondering if there's a way to dynamically change the color of an SVG path as an object moves along it, specifically using ScrollTrigger. I'd like the path to transition through colors as the object progresses along its path. Does anyone have experience or suggestions for achieving this effect? Essentially as the red ball goes down the path, the path behind it becomes a different color like green and when the red ball goes up from the end marker the path goes back to its original color. If there is any hints or help you can provide me that would be great. Thank you! See the Pen bGJxbxR by Samuel-Mathew-the-looper (@Samuel-Mathew-the-looper) on CodePen Link to comment Share on other sites More sharing options...
PointC Posted April 15 Share Posted April 15 Welcome to the forum. If you're talking about the whole path changing as you scroll, you'd move the trigger to the timeline and add a second tween to animate the stroke color as the ball animates. See the Pen 48ff3b51feeaaec506ed6260b59efa17 by PointC (@PointC) on CodePen If you meant the path would change to green only as far as the ball has traveled, you'd need a second green path that is drawn as you scroll. See the Pen f291cb8f00561f83216ca7df0680ea9b by PointC (@PointC) on CodePen Happy tweening. 2 Link to comment Share on other sites More sharing options...
smat-ctrl Posted April 15 Author Share Posted April 15 Thank you the second modified codepen you provided is exactly what I wanted. Is there anyway to do that without using the DrawSVG Plugin and using the free plugins provided? Link to comment Share on other sites More sharing options...
Solution PointC Posted April 15 Solution Share Posted April 15 You can set the stroke-dasharray and animate the stroke-dashoffset with CSS, but I'd recommend using drawSVG as it solves a lot of browser inconsistencies. Happy tweening. 1 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