Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7501269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:28:25+00:00 2026-05-29T20:28:25+00:00

I’ve been searching for a lightbox type solution that allows this but haven’t found

  • 0

I’ve been searching for a “lightbox” type solution that allows this but haven’t found one yet (please, suggest if you know of any).

The behavior I’m trying to recreate is just like what you’d see at Pinterest when clicking on an image. The overlay is scrollable (as in the whole overlay moves up like a page on top of a page) but the body behind the overlay is fixed.

I attempted to create this with just CSS (i.e. a div overlay on top of the whole page and body with overflow: hidden), but it doesn’t prevent div from being scrollable.

How to keep the body/page from scrolling but keep scrolling inside the fullscreen container?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:28:27+00:00Added an answer on May 29, 2026 at 8:28 pm

    Theory

    Looking at current implementation of the pinterest site (it might change in the future), when you open the overlay, a noscroll class is applied to the body element (setting overflow: hidden) making the body no longer scrollable.

    The overlay created on-the-fly or already injected in the page and made visible via display: block — it makes no difference – has position : fixed and overflow-y: scroll, with top, left, right and bottom properties set to 0: this style makes the overlay fill the whole viewport (but now we are in 2022, so you may use inset: 0 instead).

    The div inside the overlay is in position: static so the vertical scrollbar is related to that element. This is resulting in a scrollable but fixed overlay.

    When you close the overlay, you have to hide it (using display: none) and you could even remove the node via javascript (or just the content inside, it’s up to you but also depends on the nature of the content).

    The final step is to also remove the noscroll class applied to the body (so the overflow property gets back to the value it had previously)


    Code

    Codepen Example

    (it works by changing the aria-hidden attribute of the overlay in order to show and hide it and to increase its accessibility).

    Markup
    (open button)

    <button type="button" class="open-overlay">OPEN LAYER</button>
    

    (overlay and close button)

    <section class="overlay" aria-hidden="true" tabindex="-1">
      <div>
        <h2>Hello, I'm the overlayer</h2>
        ...   
        <button type="button" class="close-overlay">CLOSE LAYER</button>
      </div>
    </section>
    

    CSS

    .noscroll { 
      overflow: hidden;
    }
    
    .overlay { 
       position: fixed; 
       overflow-y: scroll;
       inset: 0; }
    
    [aria-hidden="true"]  { display: none; }
    [aria-hidden="false"] { display: block; }
    

    Javascript (vanilla-JS)

    var body = document.body,
        overlay = document.querySelector('.overlay'),
        overlayBtts = document.querySelectorAll('button[class$="overlay"]'),
        openingBtt;
        
    [].forEach.call(overlayBtts, function(btt) {
    
      btt.addEventListener('click', function() { 
         
         /* Detect the button class name */
         var overlayOpen = this.className === 'open-overlay';
         
         /* storing a reference to the opening button */
         if (overlayOpen) {
            openingBtt = this;
         }
         
         /* 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;
         
          /* forcing focus for Assistive technologies but note:
        - if your modal has just a phrase and a button move the
          focus on the button
        - if your modal has a long text inside (e.g. a privacy
          policy) move the focus on the first heading inside 
          the modal
        - otherwise just focus the modal.
    
        When you close the overlay restore the focus on the 
        button that opened the modal.
        */
        if (overlayOpen) {
           overlay.focus();
        }
        else {
           openingBtt.focus();
           openingBtt = null;
        }
    
      }, false);
    
    });
    
    /* detect Escape key when the overlay is open */
    document.body.addEventListener('keyup', (ev) => {
       if (ev.key === "Escape" && overlay.getAttribute('aria-hidden') === 'false') {
          overlay.setAttribute('aria-hidden', 'true');
          body.classList.toggle('noscroll', false);
          openingBtt.focus();
          openingBtt = null;
       }
    })
    

    Finally, here’s another example in which the overlay opens with a fade-in effect by a CSS transition applied to the opacity property. Also a padding-right is applied to avoid a reflow on the underlying text when the scrollbar disappears.

    Codepen Example (fade)

    CSS

    .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;
         inset: 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; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.