title: Scroll with two divs with different heights
body: <p>I'm want to scroll two divs at the same rate, basically if i've scrolled 25% of the first div, then the second will have scrolled the same percentage, but since they have different heights It is a bit hard to do. If anyone could help I'd be grateful.</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>var heightFirst = $('#first-div').height();
  var heightSecond = $('#second-div').height();
  
  $(window).scroll(function() {
    let offsetFirst = document.querySelector('#first-div').getBoundingClientRect().top;
  
    let offsetSecond = heightSecond * offsetFirst / heightFirst;
  
    if (offsetFirst &lt;= 0) {
      document.getElementById('second-div').style.top = offsetSecond + 'px';
    }
    else if (offsetFirst &gt;= 0) {
      document.getElementById('second-div').style.top = 200 + 'px';
    }
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#background{
    height: 3000px;
  }
  
  #first-div {
    width: 200px;
    height: 1000px;
    position: absolute;
    top: 200px;
    background: #585f50;
  }
  
  #second-div {
    width: 100px;
    height: 3000px;
    background: rgba(0, 0, 0, 0.5);
    position: absolute;
    top: 200px;
    z-index: 10;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div id="background"&gt;
    &lt;div id="first-div"&gt;&lt;/div&gt;
    &lt;div id="second-div"&gt;&lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>