Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Theory</strong></p> <p>Looking at current implementation of the pinterest site (it might change in the future), when you open the overlay a <code>noscroll</code> class is applied to the <code>body</code> element and <code>overflow: hidden</code> is set, thus <code>body</code> is no longer scrollable.</p> <p>The overlay (created on-the-fly or already inside the page and made visible via <code>display: block</code>, it makes no difference) has <code>position : fixed</code> and <code>overflow-y: scroll</code>, with <code>top</code>, <code>left</code>, <code>right</code> and <code>bottom</code> properties set to <code>0</code>: this style makes the overlay fill the whole viewport. </p> <p>The <code>div</code> inside the overlay is instead just in <code>position: static</code> then the vertical scrollbar you see is related to that element. As a result the content is scrollable but overlay remains fixed.</p> <p>When you close the zoom you hide the overlay (via <code>display: none</code>) and then you could also entirely remove it via javascript (or just the content inside, it's up to you how to inject it).</p> <p>As a final step you have to also remove the <code>noscroll</code> class to the <code>body</code> (so the overflow property returns to its initial value)</p> <hr> <p><strong>Code</strong></p> <blockquote> <p><a href="http://codepen.io/anon/pen/xZBovY?editors=0110" rel="noreferrer">Codepen Example</a> </p> </blockquote> <p>(it works by changing the <code>aria-hidden</code> attribute of the overlay in order to show and hide it and to increase its accessibility).</p> <p><strong>Markup</strong><br> <em>(open button)</em></p> <pre><code>&lt;button type="button" class="open-overlay"&gt;OPEN LAYER&lt;/button&gt; </code></pre> <p><em>(overlay and close button)</em></p> <pre><code>&lt;section class="overlay" aria-hidden="true"&gt; &lt;div&gt; &lt;h2&gt;Hello, I'm the overlayer&lt;/h2&gt; ... &lt;button type="button" class="close-overlay"&gt;CLOSE LAYER&lt;/button&gt; &lt;/div&gt; &lt;/section&gt; </code></pre> <p><strong>CSS</strong></p> <pre><code>.noscroll { overflow: hidden; } .overlay { position: fixed; overflow-y: scroll; top: 0; right: 0; bottom: 0; left: 0; } [aria-hidden="true"] { display: none; } [aria-hidden="false"] { display: block; } </code></pre> <p><strong>Javascript</strong> <em>(vanilla-JS)</em></p> <pre><code>var body = document.body, overlay = document.querySelector('.overlay'), overlayBtts = document.querySelectorAll('button[class$="overlay"]'); [].forEach.call(overlayBtts, function(btt) { btt.addEventListener('click', function() { /* Detect the button class name */ var overlayOpen = this.className === 'open-overlay'; /* Toggle the aria-hidden state on the overlay and the no-scroll class on the body */ overlay.setAttribute('aria-hidden', !overlayOpen); body.classList.toggle('noscroll', overlayOpen); /* On some mobile browser when the overlay was previously opened and scrolled, if you open it again it doesn't reset its scrollTop property */ overlay.scrollTop = 0; }, false); }); </code></pre> <hr> <p>Finally, here's another example in which the overlay opens with a fade-in effect by a CSS <code>transition</code> applied to the <code>opacity</code> property. Also a <code>padding-right</code> is applied to avoid a reflow on the underlying text when the scrollbar disappears.</p> <blockquote> <p><a href="http://codepen.io/anon/pen/ZWWgZJ?editors=0110" rel="noreferrer">Codepen Example (fade)</a> </p> </blockquote> <p><strong>CSS</strong></p> <pre><code>.noscroll { overflow: hidden; } @media (min-device-width: 1025px) { /* not strictly necessary, just an experiment for this specific example and couldn't be necessary at all on some browser */ .noscroll { padding-right: 15px; } } .overlay { position: fixed; overflow-y: scroll; top: 0; left: 0; right: 0; bottom: 0; } [aria-hidden="true"] { transition: opacity 1s, z-index 0s 1s; width: 100vw; z-index: -1; opacity: 0; } [aria-hidden="false"] { transition: opacity 1s; width: 100%; z-index: 1; opacity: 1; } </code></pre>
    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. 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