title: Prevent page scrolling to top upon adding fixed position
body: <p>I'm facing a problem where the page is scrolling to the top whenever I add my <code>.noscroll</code> class to the body. This way the scrollbar is still visible but greyed out whenever the overlay appears.</p>
  
  <p>I know that it's the addClass() function that is the cause of this because when I comment out that line, it doesn't scroll to the top when my overlay appears.</p>
  
  <p><strong>jQuery</strong></p>
  
  <pre><code>$('a').click(function(e) {
      //reset default anchor behavior
      e.preventDefault();
  
      //add noscroll class to body
      $("body").addClass("noscroll"); 
  
      //open overlay box
      openOverlayBox(); 
  });
  </code></pre>
  
  <p>The <code>openOverlayBox()</code> function is simply a full browser screen overlay with a black tint.</p>
  
  <p><strong>CSS</strong></p>
  
  <pre><code>body.noscroll{
      position: fixed;
      width: 100%;
      overflow-y: scroll;
  }
  </code></pre>
  
  <p><strong>Body HTML</strong></p>
  
  <pre><code>&lt;a href="#"&gt;Test&lt;/a&gt;
  </code></pre>
  
  <p>How can I make the scroll position stay the same after the <code>.noscroll</code> class has been added to the body?</p>
  
  <p><strong>EDIT 1:</strong> I'm trying to achieve the same as on Facebook. If you view a picture or video, the overlay appears, the scrollbar is greyed out but the scrolled position is maintained.</p>
  
  <p><strong>EDIT 2:</strong> I found a very close <a href="https://stackoverflow.com/a/16134959/1115367">solution</a> to my issue, but the only thing is that this does not grey the scrollbar out, but just removes it. Also when the content is centered in the middle, it still makes the content jump a little to the right because the scrollbar from the body is hidden.</p>
  
  <p><strong>EDIT 3:</strong> After Cuberto's answer and some research of myself I found out what needs to be done to get it working I want. However I don't have a clue how I would start doing it. But this is what should solve it. I when opening the overlay I need to set my main div on <code>position: fixed</code> and a negative top value of the scroll position. When exiting the overlay, the <code>position: fixed;</code> and <code>top</code> attribute should be removed and the same scroll position set as when the overlay was opened.</p>