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 trialchloeguttridge
16,608 Pointsjquery lightbox task my code renders differently
I am trying to complete this task and I think I follow it so far but my overlay does not show any transparency and when I first clicked on it the image was not displaying in top left as it is in the video. I'm missing something but I've no idea what.
My app.js code is:
//Problem: User when clicking on image goes to a dead end
//Solution: Create an overlay with the large image - Lightbox
var $overlay = $('<div id="overlay"></div>');
var $image = S("<img>");
$overlay.append($image);
// Add an image to overlay
$("body").append($overlay);
// An image
// A captions
// Capture the click event on a link to an image
$("#imageGallery a").click(function(event) {
event.preventDefault(); // prevents default browser behaviour
var imageLocation = $(this).attr("href");
// Update overlay with the image linked in the link
$image.attr("src", imageLocation);
// Show the overlay.
$overlay.show();
// Get child's alt attribute and set caption
});
// When overlay is clicked
$overlay.click(function() {
// Hide the overlay
$overlay.hide();
});
2 Answers
Nicholas Vogel
12,318 PointsThe issue might be in your css. Did you follow his steps in setting up your style.css file as well?
chloeguttridge
16,608 PointsThe CSS is fine. I went back through the code realised instead of $ sign I had S changed that and bingo fixed it.