title: Changing background-attachment property on scroll with jQuery
body: <p>I have a div that has a background-image with the background-attachment as fixed. I change from fixed to scroll when the div with the background images is halfway using jQuery. I seem to have got it working however when I scroll down, there seems to be jump when the property is changed. How can I avoid this jump?</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>$(window).scroll(function() {
    var halfHeight = $(window).height() / 2
    if ($(this).scrollTop() &gt;= $('.service-logo').offset().top + halfHeight) {
      $('.service-logo').addClass('bg-scroll');
    } else {
      $('.service-logo').removeClass('bg-scroll');
    }
  });</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.content {
    background: red;
    height: 1000px;
  }
  
  .content2 {
    background: black;
    height: 1000px;
  }
  
  .service-logo {
    background-image: url(https://www.w3schools.com/css/img_5terre.jpg);
    background-attachment: fixed;
    background-repeat: no-repeat;
    background-size: 200px;
    background-position: center;
  }
  
  .bg-scroll {
    background-attachment: scroll !important;
  }
  
  .content3 {
    background: green;
    height: 1000px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="content"&gt;
  
  &lt;/div&gt;
  
  &lt;div class="content2 service-logo"&gt;
  
  &lt;/div&gt;
  
  
  &lt;div class="content3"&gt;
  
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>