Windpixel Posted December 29, 2023 Share Posted December 29, 2023 I have a solution, but its not very robust and im sure this is a common thing that has been solved many times before, so asking you guys. Throughout most sites there are dark and light sections and when a fixed header has a transparent background, I want to flip/invert or change the menu elements so they contrast. In the min demo below, I have used the "is-light" class on a section to act as a trigger for the toggle event, although in the event that the hero section (top of page) is already a light background, the menu items wont toggle until a scroll event occurs to "check". Im sure there is a more robust solution, so wanting to hear what is the best thing Thanks in advance. See the Pen BabBREJ by windpixel (@windpixel) on CodePen Link to comment Share on other sites More sharing options...
Solution mvaneijgen Posted December 30, 2023 Solution Share Posted December 30, 2023 Just offset the ScrollTrigger by 1px, so that it also checks on page load. Also shouldn't you be looping to through the .is-light sections, instead of the menu elements? I've tweaked your CSS and JS a bit, the class is put on the .header and the CSS updates the elements inside the .header. I also loop through the .is-light elements, so that a ScrollTrigger is created for each section on the page. Hope it helps and happy tweening! See the Pen MWxwNXg?editors=0010 by mvaneijgen (@mvaneijgen) on CodePen 3 Link to comment Share on other sites More sharing options...
Rodrigo Posted December 30, 2023 Share Posted December 30, 2023 Hi, On top of @mvaneijgen's great advice, this video by @Carl should be a good resource to achieve this: Happy Tweening! 2 Link to comment Share on other sites More sharing options...
Windpixel Posted January 1 Author Share Posted January 1 Thanks mvaneijgen and Rodrigo, Will do a hybrid of both these suggestions 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