Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Four little additions to the selected solution:</p> <ol> <li>Apply 'noscroll' to <strong>html instead of to body</strong> to prevent double scroll bars in IE</li> <li>To <strong>check if there's actually a scroll bar</strong> before adding the 'noscroll' class. Otherwise, the site will also jump pushed by the new non-scrolling scroll bar.</li> <li>To keep any possible <strong>scrollTop</strong> so the entire page doesn't go back to the top (like Fabrizio's update, but you need to grab the value before adding the 'noscroll' class)</li> <li>Not all browsers handle scrollTop the same way as documented at <a href="http://help.dottoro.com/ljnvjiow.php" rel="noreferrer">http://help.dottoro.com/ljnvjiow.php</a></li> </ol> <p>Complete solution that seems to work for most browsers:</p> <p><strong>CSS</strong></p> <pre><code>html.noscroll { position: fixed; overflow-y: scroll; width: 100%; } </code></pre> <p><strong>Disable scroll</strong></p> <pre><code>if ($(document).height() &gt; $(window).height()) { var scrollTop = ($('html').scrollTop()) ? $('html').scrollTop() : $('body').scrollTop(); // Works for Chrome, Firefox, IE... $('html').addClass('noscroll').css('top',-scrollTop); } </code></pre> <p><strong>Enable scroll</strong></p> <pre><code>var scrollTop = parseInt($('html').css('top')); $('html').removeClass('noscroll'); $('html,body').scrollTop(-scrollTop); </code></pre> <p>Thanks to Fabrizio and Dejan for putting me on the right track and to Brodingo for <a href="https://twitter.com/Brodingo/status/29599155414" rel="noreferrer">the solution to the double scroll bar</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload