Recently, I created a basic lightbox with the following code snippet:
Here is the jQuery code:
var $overlay =$('<div class="overlay"></div>');
$('body').append($overlay);
$('img').click(function(){
$overlay.show();
});
And here is the associated CSS:
.overlay {
width: 100%;
height:100%;
background:grey;
display:none;
position: absolute;
top:0;
}
It's quite simple as I have only written code for the overlay that appears when an image is clicked and triggers the lightbox.
Now, I have a couple of questions regarding this setup:
If my webpage is longer than the screen, what code should I use to prevent scrolling when the lightbox is activated?
Is there a way to adjust the size of the lightbox $overlay so that it only fills the visible part of the screen? I have images spread throughout the webpage and want the lightbox to fill only the current viewport when triggered.