cookingsherri Posted February 7, 2023 Share Posted February 7, 2023 I have created an SVG that will cover an image. I want each polygon to randomly disappear. I have managed to get the classes to randomly disappear, but I don't know how to target the individual polygons. How would I do that? I thought of nth-of-type, but I am not sure how to get it to work. Any ideas? See the Pen xxJmjEr by cookingsherri (@cookingsherri) on CodePen Link to comment Share on other sites More sharing options...
Carl Posted February 7, 2023 Share Posted February 7, 2023 welcome to the GreenSock forums. thank you for the minimal demo. I don't think you can target unique instances of objects that repeat in a pattern like that. With what you have I think this is the easiest way to randomize it a bit See the Pen rNrgBqm?editors=0110 by snorkltv (@snorkltv) on CodePen The only option I know is to programatically create the grid so that each polygon is it's own entity in the svg. There's a chance I'm wrong, and if so, I welcome other ideas. 2 Link to comment Share on other sites More sharing options...
elegantseagulls Posted February 7, 2023 Share Posted February 7, 2023 2 hours ago, cookingsherri said: Any ideas? @Carl is correct, you cannot target individual pieces of a pattern. Also, if you are animating pieces of SVG patterns, the performance is really really bad (from personal experience). 4 Link to comment Share on other sites More sharing options...
elegantseagulls Posted February 7, 2023 Share Posted February 7, 2023 Your best bet is to create the SVG polygons not inside a pattern (it will be more markup, but will be much more performant). If you need to do this for different sizes, you'll just want to dynamically generate the SVG and the polygons based on size of container. 1 Link to comment Share on other sites More sharing options...
Solution Carl Posted February 8, 2023 Solution Share Posted February 8, 2023 being that I just did a lesson on cloning groups in my SVG Animation with GreenSock course, I figured I'd take a stab at this. The top-level approach was: take polygons out of pattern in defs wrap them in a group create a loop-inside-a-loop to clone the initial group and place the clones in a grid animate using same technique as above See the Pen ZEjNvKw?editors=1010 by snorkltv (@snorkltv) on CodePen Hope this helps 5 Link to comment Share on other sites More sharing options...
cookingsherri Posted March 15, 2023 Author Share Posted March 15, 2023 This is fantastic! Thank you so much. This is exactly what I wanted to do. I can't get it working in my project. I have added the following : <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.4/gsap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.4/ScrollTrigger.min.js"></script> <script src="js/svg-reveal.js"></script> But it isn't working. This is my first time using Greensock. Can you help me? Link to comment Share on other sites More sharing options...
cookingsherri Posted March 15, 2023 Author Share Posted March 15, 2023 I figured it out. Rookie mistake. When I created my svg-reveal file it was mistakenly inside another file. Doh! 1 Link to comment Share on other sites More sharing options...
Cassie Posted March 15, 2023 Share Posted March 15, 2023 Glad you got it sorted! 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