locomotive-scroll
locomotive-scroll copied to clipboard
background colour
Hello
I can't find where I can change the bg color when scrolling Can you help me?
Thank you 👊
similar #171
This work for me!
HTML code
<div id="body" data-scroll-container>
<section class="box-item" data-scroll-section>
<div class="box-item-content" data-scroll data-scroll-repeat data-scroll-call="colorWhite">
<p>Text....</p>
</div>
</section>
<section class="box-item" data-scroll-section>
<div class="box-item-content" data-scroll data-scroll-repeat data-scroll-call="colorBlack">
<p>Text....</p>
</div>
</section>
</div>
CSS Style
#body {
transition: background-color 1s ease;
}
JS Code
const scroller = new LocomotiveScroll({
el: document.querySelector('[data-scroll-container]'),
smooth: true
});
scroller.on('call', (value, way, obj) => {
if (way === 'enter') {
switch (value) {
case "colorWhite":
document.querySelector('#body').style.backgroundColor = "#FFFFFF";
break;
case "colorBlack":
document.querySelector('#body').style.backgroundColor = "#000000";
break;
}
}
});