.dark-bg
, .light-bg
)..invert
CSS class using filter: invert(1)
and use JavaScript to detect the active slide and toggle the .invert
class on the logo and menu button based on the slide’s background.To dynamically invert the colors of your logo and menu button in Webflow based on the background color of your slider, you'll need to use JavaScript to detect changes and apply a class or invert styles automatically.
#logo
, #menu-btn
)..dark-bg
, .light-bg
) so the script can detect whether to invert.Create a CSS class in your Webflow project (in the Custom Code area > inside <style>
tags in the <head>
section):
Example:
```css
.invert {
filter: invert(1) hue-rotate(180deg);
}
```
This will visually invert white to black and vice versa for most elements like logo and icons.
tag, add JavaScript to:
.invert
on the logo and menu button automatically.Example:
<script> const logo = document.getElementById('logo'); const menuBtn = document.getElementById('menu-btn'); const slider = document.querySelector('.w-slider'); function updateInversion() { const activeSlide = document.querySelector('.w-slide[aria-hidden="false"]'); if (activeSlide && activeSlide.classList.contains('dark-bg')) { logo.classList.add('invert'); menuBtn.classList.add('invert'); } else { logo.classList.remove('invert'); menuBtn.classList.remove('invert'); } } // Run on page load updateInversion(); // Monitor slider change const observer = new MutationObserver(updateInversion); observer.observe(document.querySelector('.w-slider-mask'), { attributes: true, subtree: true }); // Fallback on slide clicks/arrows document.querySelectorAll('.w-slider-arrow-left, .w-slider-arrow-right').forEach(btn => { btn.addEventListener('click', () => setTimeout(updateInversion, 100)); });</script>
To invert your logo and menu button colors based on slider background in Webflow, add identifiable classes to slides, create an .invert
CSS class with filter: invert(1), and use JavaScript to detect the active slide and toggle the class in real time based on its background class. This ensures your UI adapts dynamically without manual intervention.