locomotive-scroll icon indicating copy to clipboard operation
locomotive-scroll copied to clipboard

background colour

Open Shay1011 opened this issue 3 years ago • 2 comments

Hello

I can't find where I can change the bg color when scrolling Can you help me?

Thank you 👊

Shay1011 avatar Nov 23 '21 13:11 Shay1011

similar #171

Dushyant1295 avatar Nov 23 '21 15:11 Dushyant1295

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;          
    }
  } 
});

carlosvolp avatar Apr 06 '23 19:04 carlosvolp