Wondering if anyone can point me in the right direction. I would like to have a top nav change to either light or dark, depending on the image underneath which is in a slider. So, if the slide image is dark, the nav would change to white. If the slide image is light, the nav would change to dark.
Typically the nav and the slider wonât be nested within each other, which can make it difficult to use CSS selectors here. Iâd go with a JS approach.
Letâs say your default display is âlightâ mode nav.
Create your light mode nav, and then create a variation of it where every relevant element has a subclass of is-dark, and style that variant accordingly.
Similarly, give your dark slides a subclass of e.g. is-dark to identify them.
Use SA5âs slider to easily get the slide changed events, no matter whether itâs user-changed or auto-changed.
Then in the slideChanged event, youâd just check the current slideâs class list for is-dark, and update your relevant nav elements accordingly by adding/removing that is-dark subclass.
Thanks again for your suggestions. I used the sygnal slider element and I got some of it to work. Currently the console is showing the slides are changing. My issue now is Iâm not sure how to identify a dark or light slide, and then how do I communicate that to the nav.
My thought is, since Iâm also using Waypoint.js for my nav colour change, I wonder if I can use some of that code to change the nav to light or dark.
For example, I would like to re-use this code:
if (direction == âdownâ ) {
$(â.brandâ).addClass(ânowâwhiteâ);
$(â.navbar1_link.blackâ).addClass(ânowâwhiteâ);
}
But instead of âdirection downâ, I would need something else, like if âslide.is-darkâ then do the thing.
Iâm not sure where to put the .is-dark or .is-light class. I tried adding it to the slide element.
Another issue I just thought of, once this is working, my nav will probably change colours even when the slider is out of the viewport, which is not what I want. I will need to think about this.