Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Don't allow to scroll the page when popup shows

Hey all, I have a problem with my current image gallery. When someone clicks on the thumbnail the hidden big div shows the enlarged picture (like a popup). I have a semi transparent div over the whole page then to darken it out.

Now I would like to disable the scrolling of the page, while the div is showing. I have to do it with javascript no jquery though as it is for a school project.

Any ideas?

3 Answers

Can you post your code?

Hey Aaron, thanks for the reply, this is my code atm:

js:

var scrollThePage;

function scrollToTop() {
        if (scrollThePage == null) {
        var scrollStep = -window.scrollY / 25;
        scrollThePage = setInterval(function(){
        if ( window.scrollY > 0 ) {
            window.scrollBy( 0, scrollStep );
        }
        else { 
            clearInterval(scrollThePage);
            scrollThePage = null;
        } 
    },25);
}
}

and in html it is:

  <div id="scrollToTop" onclick="scrollToTop()">
                <p>&nbsp;</p>
            </div>

I am not sure on the answer for that.