user2993018 user2993018 - 6 months ago 8
HTML Question

How do I make my lightbox not scroll?

http://www.markthatred.com/ I have this site when you go to the my works section and click a thumbnail a lightbox will appear it's working fine but how can I make it not non-scrollable while it is on lightbox?

html

<!-- thumbnail image wrapped in a link -->
<a href="#img1">
<img alt="Eiffel Tower Web Design Mockup - Mark That RedWeb Design Mockup" class="works-feature-thumb" src="images/lightbox-1-t.jpg"/>
</a>
<!-- lightbox container hidden with CSS -->
<a href="#_" class="lightbox" id="img1">
<img alt="Law Attorney Web Design Mockup - Mark That Red Web Design Mockup Philippines" src="images/lightbox-1.jpg"/>
</a>


css

.lightbox {
/** Default lightbox to hidden */
display: none;

/** Position and style */
position: fixed;
z-index: 999;
width: 100%;
height: 100%;
text-align: center;
top: 0;
left: 0;
background: rgba(0,0,0,0.8);
}

.lightbox img {
/** Pad the lightbox image */
max-width: 95%;
max-height: 90%;
margin-top: 2%;
}

.lightbox img:hover {
opacity: 1;
}

.lightbox:target {
/** Remove default browser outline */
outline: none;

/** Unhide lightbox **/
display: block;
overflow: hidden;
}

Answer

If you add this script it will work.

$(document).ready(function(){
    $(".works-feature").click(function(){
        $("body").css("overflow","hidden");
    });
    $(".lightbox").click(function(){
        $("body").css("overflow","auto");
    });
});