data-theme attribute (light or dark) to each slide..invert class on the logo/menu elements..invert class in CSS to visually adjust the logo and menu as needed (e.g., using filter or color changes).To dynamically invert your logo and menu button colors in Webflow based on the background of a slider (e.g. light vs dark slide), you’ll need to use a small custom script that detects each slide’s background and adjusts the color styles in real time.
.site-logo and .menu-button..slider-slide) and a background color or an identifying attribute for color contrast logic.data-theme="dark" or data-theme="light".
data-themedark or light, depending on the contrast needed for your UI elements.
Description of the logic:
data-theme value of the target slide..invert on logo/menu button to change their styles.
Example script:
<script> tag:
`document.addEventListener('DOMContentLoaded', function () {
const slider = document.querySelector('.w-slider');
const logo = document.querySelector('.site-logo');
const menu = document.querySelector('.menu-button');
function updateTheme() {
const activeSlide = slider.querySelector('.w-slider-mask > .w-slide[aria-hidden="false"]');
if (!activeSlide) return;
const theme = activeSlide.getAttribute('data-theme');
if (theme === 'dark') {
logo.classList.add('invert');
menu.classList.add('invert');
} else {
logo.classList.remove('invert');
menu.classList.remove('invert');
}
}
// Initial check
updateTheme();
// Re-check on each slide change
slider.addEventListener('slide.bs.carousel', updateTheme);
const observer = new MutationObserver(updateTheme);
observer.observe(slider, { childList: true, subtree: true, attributes: true });
});`
.invert:.invert { filter: invert(1); } or.invert { color: #fff; fill: #fff; } depending on the element type.fill or filter changes.
data-theme="dark" is active, your logo and menu button respond accordingly.
To invert your logo and menu button in Webflow based on your slider's background in real time, use data attributes (like data-theme) on slides and a custom script that adds or removes an .invert class based on the active slide. This ensures dynamic, automatic inversion without manual updates.