title: Locomotive Scroll get elements position
body: <p>I am using Locomotive Scroll for a smooth scroll effect.</p>
  <p>I need to change the background-color and the color of the whole HTML when reaching a certain section.
  At the moment I am using the call event on locomotive to add a custom function called 'updateBg' and when it is called I change wrapper's background and color.</p>
  <p>The tricky part is that if the section is still in the viewport and I reverse the scroll it will not change the colors.</p>
  <p>Example:
  If I scroll to the second intro section (AND the first intro is in the viewport) it will change to a black background. But if I scroll up it will not change to a white background as the section did not get out from the viewport and the last call was with a black background.</p>
  <p>You have to completely pass through a section to be able to reverse the colors.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const initLocomotiveScroll = () =&gt; {
    const wrapper = document.querySelector('.wrapper')
  
    const locoScroll = new LocomotiveScroll({
      el: document.querySelector('[data-scroll-container]'),
      smooth: true
    })
  
    locoScroll.on('call', (func, dir, obj) =&gt; {
      const {
        el
      } = obj
  
      if ('updateBg' === func) {
        const bg = el.getAttribute('data-bg')
        const color = el.getAttribute('data-color')
  
        if (dir === 'enter') {
          wrapper.style.backgroundColor = bg
          wrapper.style.color = color
        }
      }
    })
  }
  
  setTimeout(() =&gt; {
    initLocomotiveScroll()
  }, 1000);</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>/* ------------------------------------------------------------ *\
      Base
  \* ------------------------------------------------------------ */
  
  html {
    background: #fff;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.4;
    color: #000;
  }
  
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    margin-bottom: 1rem;
  }
  
  h1 {
    margin-bottom: 20px;
    font-size: 50px;
    font-weight: 800;
    line-height: 1.44;
  }
  
  h2 {
    font-size: 36px;
    line-height: 1.1667;
  }
  
  h3 {
    font-size: 24px;
    font-weight: 800;
  }
  
  h4 {
    font-size: 18px;
    font-weight: 600;
  }
  
  h5 {
    margin-bottom: 10px;
    font-size: 16px;
    font-weight: 600;
    text-transform: uppercase;
  }
  
  h6 {
    font-size: 14px;
  }
  
  p {
    margin-bottom: 1rem;
    &amp;:last-child {
      margin-bottom: 0;
    }
  }
  
  .text-large {
    font-size: 24px;
    line-height: 1.7;
  }
  
  
  /* ------------------------------------------------------------ *\
      Wrapper
  \* ------------------------------------------------------------ */
  
  .wrapper {
    overflow: hidden;
    min-height: 100vh;
    padding-top: 90px;
    background: #fff;
    color: #000;
    backface-visibility: hidden;
    transition: background-color .4s ease-in, color .4s ease-in;
    will-change: background-color, color;
  }
  
  
  /* ------------------------------------------------------------ *\
      Container
  \* ------------------------------------------------------------ */
  
  .container {
    width: 100%;
    max-width: 1156px;
    padding: 0 60px;
    margin: 0 auto;
  }
  
  
  /* ------------------------------------------------------------ *\
      Fullsize Image
  \* ------------------------------------------------------------ */
  
  .fullsize-image {
    position: relative;
    display: block;
    background-position: 50% 50%;
    background-size: cover;
    background-repeat: no-repeat;
    &amp;&gt;img {
      position: absolute;
      top: 0;
      left: 0;
      height: 1px;
      width: 1px;
      opacity: 0;
    }
  }
  
  
  /* ------------------------------------------------------------ *\
      Intro
  \* ------------------------------------------------------------ */
  
  .intro {
    position: relative;
    padding: 105px 0;
    &amp;__content {
      max-width: 800px;
    }
    &amp;__entry {
      max-width: 520px;
      margin-bottom: 15px;
    }
  }
  
  
  /* ------------------------------------------------------------ *\
      Section Gutter
  \* ------------------------------------------------------------ */
  
  .section-gutter {
    padding: 50px 0;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdn.jsdelivr.net/npm/locomotive-scroll@3.5.4/dist/locomotive-scroll.min.js"&gt;&lt;/script&gt;
  &lt;div class="wrapper" data-scroll-container&gt;
    &lt;main class="main"&gt;
      &lt;div data-scroll-section&gt;
        &lt;section class="intro" data-scroll data-bg="#ffffff" data-color="#000000" data-scroll-repeat="true" data-scroll-call="updateBg"&gt;
          &lt;div class="container"&gt;
            &lt;div class="intro__content"&gt;
              &lt;h5 class="intro__subtitle"&gt;
                &lt;span&gt;Lorem ipsum dolor.&lt;/span&gt;
              &lt;/h5&gt;
  
              &lt;h2 class="intro__title"&gt;If I scroll to the second intro section (AND the first intro is in the viewport) it will change to a black background. But if I scroll up it will not change to a white background as the section did not get out from the viewport and the last
                call was with a black background.&lt;/h2&gt;
  
              &lt;p&gt;You have to completely pass through a section to be able to reverse back the colors.&lt;/p&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/section&gt;
      &lt;/div&gt;
  
      &lt;div data-scroll-section&gt;
        &lt;div class="section-gutter"&gt;
          &lt;div class="container"&gt;
            &lt;h1&gt;This is section just for gutters&lt;/h1&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div data-scroll-section&gt;
        &lt;section class="intro" data-scroll data-bg="#000000" data-color="#ffffff" data-scroll-repeat="true" data-scroll-call="updateBg"&gt;
          &lt;div class="container"&gt;
            &lt;div class="intro__content"&gt;
              &lt;h5 class="intro__subtitle"&gt;
                &lt;span&gt;Lorem ipsum dolor.&lt;/span&gt;
              &lt;/h5&gt;
  
              &lt;h1 class="intro__title"&gt;There is some kind of bug for changing the colors of the next sections, but they are not part of the main problem. On real project, it is working correctly.&lt;/h1&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/section&gt;
      &lt;/div&gt;
  
      &lt;div data-scroll-section&gt;
        &lt;div class="section-gutter"&gt;
          &lt;div class="container"&gt;
            &lt;h1&gt;This is section just for gutters&lt;/h1&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div data-scroll-section&gt;
        &lt;section class="intro" data-scroll data-bg="#ffffff" data-color="#000000" data-scroll-repeat="true" data-scroll-call="updateBg"&gt;
          &lt;div class="container"&gt;
            &lt;div class="intro__content"&gt;
              &lt;h5 class="intro__subtitle"&gt;
                &lt;span&gt;Lorem ipsum dolor.&lt;/span&gt;
              &lt;/h5&gt;
  
              &lt;h1 class="intro__title"&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore, asperiores?&lt;/h1&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/section&gt;
      &lt;/div&gt;
  
      &lt;div data-scroll-section&gt;
        &lt;div class="section-gutter"&gt;
          &lt;div class="container"&gt;
            &lt;h1&gt;This is section just for gutters&lt;/h1&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div data-scroll-section&gt;
        &lt;section class="intro" data-scroll data-bg="#000000" data-color="#ffffff" data-scroll-repeat="true" data-scroll-call="updateBg"&gt;
          &lt;div class="container"&gt;
            &lt;div class="intro__content"&gt;
              &lt;h5 class="intro__subtitle"&gt;
                &lt;span&gt;Lorem ipsum dolor.&lt;/span&gt;
              &lt;/h5&gt;
  
              &lt;h1 class="intro__title"&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit. Inventore, asperiores?&lt;/h1&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/section&gt;
      &lt;/div&gt;
    &lt;/main&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  <p>The only approach I think that what will work is to find the sections offset top and to set the colors based on section's offset top and locomotive's scroll delta. The problem is that the only place I can take their offsets is when call event is triggered.</p>
  <p>How can I take all of the sections offset tops on load?
  Can somebody think up another workaround?</p>