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 trialSaloni Mude
9,933 PointsOverlay not working in neither Chrome nor Firefox
I've written the code down exactly like it is shown in the video. My code worked initially when I set the bakcground to only black , but since I changed it to rgba it doesn't work anymore.Even more oddly , now even if I set it back to black, it won't show up anymore. I tried both Chrome and Firefox.
Here's the Index.html file:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
<title>Image Gallery</title>
</head>
<body>
<h1>Image Gallery</h1>
<ul id="imageGallery">
<li><a href="images/refferal_machine.png"><img src="images/refferal_machine.png" width="100" alt="Refferal Machine By Matthew Spiel"></a></li>
<li><a href="images/space-juice.png"><img src="images/space-juice.png" width="100" alt="Space Juice by Mat Helme"></a></li>
<li><a href="images/education.png"><img src="images/education.png" width="100" alt="Education by Chris Michel"></a></li>
<li><a href="images/copy_mcrepeatsalot.png"><img src="images/copy_mcrepeatsalot.png" width="100" alt="Wanted: Copy McRepeatsalot by Chris Michel"></a></li>
<li><a href="images/sebastian.png"><img src="images/sebastian.png" width="100" alt="Sebastian by Mat Helme"></a></li>
<li><a href="images/skill-polish.png"><img src="images/skill-polish.png" width="100" alt="Skill Polish by Chris Michel"></a></li>
<li><a href="images/chuck.png"><img src="images/chuck.png" width="100" alt="Chuck by Mat Helme"></a></li>
<li><a href="images/library.png"><img src="images/library.png" width="100" alt="Library by Tyson Rosage"></a></li>
<li><a href="images/boat.png"><img src="images/boat.png" width="100" alt="Boat by Griffin Moore"></a></li>
<li><a href="images/illustrator_foundations.png"><img src="images/illustrator_foundations.png" width="100" alt="Illustrator Foundations by Matthew Spiel"></a></li>
<li><a href="images/treehouse_shop.jpg"><img src="images/treehouse_shop.jpg" width="100" alt="Treehouse Shop by Eric Smith"></a></li>
</ul>
<script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/app.js" type="text/javascript" charset="utf-8"></script>
</body>
</html>
Here's the style.css File :
body {
font-family: sans-serif;
background: #384047;
}
h1 {
color: #fff;
text-align: center
}
ul {
list-style:none;
margin: 0 auto;
padding: 0;
display: block;
max-width: 780px;
text-align: center;
}
ul li {
display: inline-block;
padding: 8px;
background:white;
margin:10px;
}
ul li img {
display: block;
}
a {
text-decoration: none;
}
/** Start Coding Here **/
#overlay {
background:rgba(0,0,0,0.7);
width:100%;
height:100%;
position:absolute;
top:0;
left:0;
display:none;
}
and here's the js file
//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>');
//Add overlay
$("body").append($overlay);
//An image
//A caption
//Capture the click event on a link to an image
$("#imageGallery a").click(function(event){
event.preventDefault();
var href = $(this).attr("href");
$overlay.show()
//Show the overlay.
//Update overlay with the image linked in the link
//Get child's alt attribute and set caption
});
//When overlay is clicked
//Hide the overlay
6 Answers
robbertdekock
13,390 PointsI've experienced the same problem and I think I've found the right solution. The command $overlay.show(); gives an error in my console when i click on the image. The error message is "$overlay.show is not a function. The target of the function is a var that contains the HTML for the div, but you don't want to run the code on the var, you want to run the code on the HTML you've created before. So you'll have to target the id of the created HTML code using the following code.
$("#overlay").show();
I hope this helps for the rest of you following this course, at least it worked for me. :)
David Dehghani
6,992 PointsExact same thing happened to me and I tripe checked to make sure my code was identical. You're not the only one!
I tried this as well but to no avail: background: black; opacity: 70%;
Sorry!
Ozgur Parlakkilic
8,399 PointsSame here. Doesnt work. I wonder why.
Lucas Gallindo
1,781 PointsDid u guys found the reason for that? Same problem here.
Chris Fitzgerald
5,897 PointsSame here...No luck in Chrome!
mohammed mayat
4,228 Pointsi am having same problem,
Anastasia Okuntseva
11,477 PointsI've had the same problem, but after checking java script console in dev tools I've caught some minor sintax error(happens all the time to me). Looks like you are missing semicolon after - $overlay.show();