data-bg
attribute (e.g., "light" or "dark") to each slider slide and assign identifiable classes to logo and menu elements..invert
class on logo and menu based on the slide’s data-bg
..invert
class in Webflow (e.g., filter: invert(1)
or color change), then test across all slides to confirm dynamic color inversion works properly.To dynamically invert the colors of your logo and menu button in Webflow based on the background color of your slider (and without manual triggers), you'll need to use custom JavaScript to detect background changes and apply corresponding style changes.
.logo
, .menu-button
).data-bg
attribute to each slider slide, like data-bg="light"
or data-bg="dark"
, to manually define color intent without needing color detection.<script> const invertElements = () => { const slides = document.querySelectorAll('.w-slide'); const logo = document.querySelector('.logo'); const menu = document.querySelector('.menu-button'); const observer = new MutationObserver(() => { slides.forEach(slide => { if (slide.classList.contains('w--current')) { const bg = slide.getAttribute('data-bg'); if (bg === 'dark') { logo.classList.add('invert'); menu.classList.add('invert'); } else { logo.classList.remove('invert'); menu.classList.remove('invert'); } } }); }); // Observe for class changes that indicate slide changes slides.forEach(slide => { observer.observe(slide, { attributes: true, attributeFilter: ['class'] }); }); }; document.addEventListener('DOMContentLoaded', invertElements);</script>
.invert
Class in Webflow.invert
for your logo and menu.filter: invert(1)
if it's an image.color: white
or black
as needed.data-bg
value (light
or dark
).To invert your logo and menu color dynamically in Webflow, use data attributes on each slide, a MutationObserver in JavaScript to track visible slides, and a custom .invert
class to style elements based on background intent. This ensures a real-time, automatic, and maintainable color toggle without manual intervention.