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 trialJacob Shore
3,918 Points*[SOLVED]* Overlay doesn't take up whole page
I wrote the code but the overlay does not cover the page: it only takes up the size of the image:
the CSS
#overlay {
background-color: rgba(0,0,0,0.7);
width: 100%;
height: 100;
position: absolute;
top: 0;
left:0;
display:none;
z-index: 1;
}
the jQuery
//Problem: User when clicking on image goes to a dead end
// Solution: Create and overlay with large image - Lightbox
var $overlay = $('<div id="overlay"></div>');
var $image = $("<img>");
$overlay.append($image);
$("body").append($overlay);
// 1. capture the click event on a link to an image
$("#imageGallery a").click(function(e) {
e.preventDefault();
var imgLocation = $(this).attr("href");
//1.2 update overlay with the image linked in the link
$image.attr("src", imgLocation);
$overlay.show();
//1.1 show the overlay
//1.2 update overlay with the image linked in the link
//1.3 Get child's alt attribute and set caption
// 2. Add an overlay
//2.1 An image
//2.2 A caption
// 3. When overlay is clicked
// 3.1 Hide overlay
});
why!?
1 Answer
Jacob Shore
3,918 PointsOK, I figured it out - I left out the "%" for the height value in my CSS! Oh well, I'm leaving it up in case it happens to someone else.