I want to add a clickable image in my html page, with opacity and when I hover with my mouse over the image, the opacity has to change to 0. (with a: hover)
I tried different methods, but not one works..
Can anyone give me the code?
I found out how to fix the problem:
<html>
<div id="yourdiv">
<a href="#">
<img src="images/yourimage.png" width="20" height="20" alt="..." />
</a>
</div>
</html>
<style>
#yourdiv img{
opacity:0.5;
filter:alpha(opacity=50); /* For IE8 and earlier */
}
#yourdiv img:hover{
opacity:1.0;
filter:alpha(opacity=100); /* For IE8 and earlier */
}
</style>
Have you tried at least googling your issue?
Doesn't seem so...
http://www.webdesign.org/html-and-css/tutorials/images-with-hover-effects.9130.html
Related
I want to overlay one image with another using CSS. An example of this is the first image (the background if you like) will be a thumbnail link of a product, with the link opening a lightbox / popup showing a larger version of the image.
On top of this linked image I would like an image of a magnifying glass, to show people that the image can be clicked to enlarge it (apparently this isn't obvious without the magnifying glass).
I just got done doing this exact thing in a project. The HTML side looked a bit like this:
<a href="[fullsize]" class="gallerypic" title="">
<img src="[thumbnail pic]" height="90" width="140" alt="[Gallery Photo]" class="pic" />
<span class="zoom-icon">
<img src="/images/misc/zoom.gif" width="32" height="32" alt="Zoom">
</span>
</a>
Then using CSS:
a.gallerypic{
width:140px;
text-decoration:none;
position:relative;
display:block;
border:1px solid #666;
padding:3px;
margin-right:5px;
float:left;
}
a.gallerypic span.zoom-icon{
visibility:hidden;
position:absolute;
left:40%;
top:35%;
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}
a.gallerypic:hover span.zoom-icon{
visibility:visible;
}
I left a lot of the sample in there on the CSS so you can see how I decided to do the style. Note I lowered the opacity so you could see through the magnifying glass.
EDIT: To clarify for your example - you could ignore the visibility:hidden; and kill the :hover execution if you wanted, this was just the way I did it.
One technique, suggested by this article, would be to do this:
<img style="background:url(thumbnail1.jpg)" src="magnifying_glass.png" />
A simple way of doing that with CSS
only without modifying the content
with additional tags is shown here
(with code and example):
http://soukie.net/2009/08/20/typography-and-css/#example
This works, as long as the parent element is not using static positioning. Simply setting it to relative positioning does the trick. Also, IE <8 don't support the :before selector or content.
Edit:
Link above no longer works but is visible on the WayBack Machine:
https://web.archive.org/web/20120213121217/https://soukie.net/2009/08/20/typography-and-css/
Here is how I did it recently. Not perfect semantically, but gets the job done.
<div class="container" style="position: relative">
<img style="z-index: 32; left: 8px; position: relative;" alt="bottom image" src="images/bottom-image.jpg">
<div style="z-index: 100; left: 72px; position: absolute; top: 39px">
<img alt="top image" src="images/top-image.jpg"></div></div>
You might want to check out this tutorial:
http://www.webdesignerwall.com/tutorials/css-decorative-gallery/
In it the writer uses an empty span element to add an overlaying image. You can use jQuery to inject said span elements, if you'd like to keep your code as clean as possible. An example is also given in the aforementioned article.
Hope this helps!
-Dave
If you're only wanting the magnifing glass on hover then you can use
a:hover img { cursor: url(glass.cur); }
http://www.javascriptkit.com/dhtmltutors/csscursors.shtml
If you want it there permanently you should probably either have it included in the original thumnail, or add it using JavaScript rather than adding it to the HTML (this is purely style and shouldn't be in the content).
Let me know if you want help on the JavaScript side.
In CSS3, you can do the following:
.double-image {
background-image: url(images/img1.png), url(images/img2.png);
}
Took from Can I have multiple background images using CSS?
All we want is parent above child. This is how you do it.
You put img into span, set z-index & position for both elements, and extra display for span. Add hover to span so you can test it and you got it!
HTML:
<span><img src="/images/"></span>
CSS
span img {
position:relative;
z-index:-1;
}
span {
position:relative;
z-index:initial;
display:inline-block;
}
span:hover {
background-color:#000;
}
Unless you use the <img> tag, which displays an image by itself, you will not be able to achieve this with pure CSS alone. You will also need TWO HTML elements as well - one for each picture. This is because the only way you can make an element display a picture via CSS is with the background-image property, and every element can have only one background image. Which two elements you choose and how you position them is up to you. There are many ways how you can position one HTML element above another.
Here's a good technique to display an overlay image that is centered with a semi-transparent background over an image link:
HTML
<div class="image-container">
<a class="link" href="#" >
<img class="image" src="/img/thumbnail.png"/>
<span class="overlay-image"><img src="/img/overlay.png"></span>
</a>
</div>
CSS
div.image-container{
position: relative;
}
a.link{
text-decoration: none;
position: relative;
display: block;
}
a.link span.overlay-image{
visibility: hidden;
position: absolute;
left: 0px;
top: 0px;
bottom: 0px;
right: 0px;
background-color: rgba(0,0,0,0.2); /* black background with 20% alpha */
}
a.link span.overlay-image:before { /* create a full-height inline block pseudo=element */
content: ' ';
display: inline-block;
vertical-align: middle; /* vertical alignment of the inline element */
height: 100%;
}
a.link:hover span.overlay-image img{
display: inline-block;
vertical-align: middle;
}
a.link:hover span.overlay-image{
visibility: visible;
}
Here's a JQuery Technique with semi-transparent background.
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><img src="images/refferal_machine.png" width="100" alt="Refferal Machine By Matthew Spiel"></li>
<li><img src="images/space-juice.png" width="100" alt="Space Juice by Mat Helme"></li>
<li><img src="images/education.png" width="100" alt="Education by Chris Michel"></li>
<li><img src="images/copy_mcrepeatsalot.png" width="100" alt="Wanted: Copy McRepeatsalot by Chris Michel"></li>
<li><img src="images/sebastian.png" width="100" alt="Sebastian by Mat Helme"></li>
<li><img src="images/skill-polish.png" width="100" alt="Skill Polish by Chris Michel"></li>
<li><img src="images/chuck.png" width="100" alt="Chuck by Mat Helme"></li>
<li><img src="images/library.png" width="100" alt="Library by Tyson Rosage"></li>
<li><img src="images/boat.png" width="100" alt="Boat by Griffin Moore"></li>
<li><img src="images/illustrator_foundations.png" width="100" alt="Illustrator Foundations by Matthew Spiel"></li>
<li><img src="images/treehouse_shop.jpg" width="100" alt="Treehouse Shop by Eric Smith"></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>
CSS
/** Start Coding Here **/
#overlay {
background:rgba(0,0,0,0.7);
width:100%;
height:100%;
position:absolute;
top:0;
left:0;
display:none;
text-align:center;
}
#overlay img {
margin-top: 10%;
}
#overlay p {
color:white;
}
app.js
var $overlay = $('<div id="overlay"></div>');
var $image = $("<img>");
var $caption = $("<p></p>");
// 1. Capture the click event on a link to an image
$("#imageGallery a").click(function(event){
event.preventDefault();
var imageLocation = $(this).attr("href");
// 1.1 Show the overlay.
$overlay.show();
// 1.2 Update overlay with the image linked in the link
$image.attr("src", imageLocation);
// 1.3 Get child's alt attribute and set caption
var captionText = $(this).children("img").attr("alt");
$caption.text(captionText);
// 2. Add overlay
$("body").append($overlay);
// 2.1 An image to overlay
$overlay.append($image);
// 2.2 A caption to overlay
$overlay.append($caption);
});
//When overlay is clicked
$overlay.click(function(){
//Hide the overlay
$overlay.hide();
});
I want to overlay one image with another using CSS. An example of this is the first image (the background if you like) will be a thumbnail link of a product, with the link opening a lightbox / popup showing a larger version of the image.
On top of this linked image I would like an image of a magnifying glass, to show people that the image can be clicked to enlarge it (apparently this isn't obvious without the magnifying glass).
I just got done doing this exact thing in a project. The HTML side looked a bit like this:
<a href="[fullsize]" class="gallerypic" title="">
<img src="[thumbnail pic]" height="90" width="140" alt="[Gallery Photo]" class="pic" />
<span class="zoom-icon">
<img src="/images/misc/zoom.gif" width="32" height="32" alt="Zoom">
</span>
</a>
Then using CSS:
a.gallerypic{
width:140px;
text-decoration:none;
position:relative;
display:block;
border:1px solid #666;
padding:3px;
margin-right:5px;
float:left;
}
a.gallerypic span.zoom-icon{
visibility:hidden;
position:absolute;
left:40%;
top:35%;
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}
a.gallerypic:hover span.zoom-icon{
visibility:visible;
}
I left a lot of the sample in there on the CSS so you can see how I decided to do the style. Note I lowered the opacity so you could see through the magnifying glass.
EDIT: To clarify for your example - you could ignore the visibility:hidden; and kill the :hover execution if you wanted, this was just the way I did it.
One technique, suggested by this article, would be to do this:
<img style="background:url(thumbnail1.jpg)" src="magnifying_glass.png" />
A simple way of doing that with CSS
only without modifying the content
with additional tags is shown here
(with code and example):
http://soukie.net/2009/08/20/typography-and-css/#example
This works, as long as the parent element is not using static positioning. Simply setting it to relative positioning does the trick. Also, IE <8 don't support the :before selector or content.
Edit:
Link above no longer works but is visible on the WayBack Machine:
https://web.archive.org/web/20120213121217/https://soukie.net/2009/08/20/typography-and-css/
Here is how I did it recently. Not perfect semantically, but gets the job done.
<div class="container" style="position: relative">
<img style="z-index: 32; left: 8px; position: relative;" alt="bottom image" src="images/bottom-image.jpg">
<div style="z-index: 100; left: 72px; position: absolute; top: 39px">
<img alt="top image" src="images/top-image.jpg"></div></div>
You might want to check out this tutorial:
http://www.webdesignerwall.com/tutorials/css-decorative-gallery/
In it the writer uses an empty span element to add an overlaying image. You can use jQuery to inject said span elements, if you'd like to keep your code as clean as possible. An example is also given in the aforementioned article.
Hope this helps!
-Dave
If you're only wanting the magnifing glass on hover then you can use
a:hover img { cursor: url(glass.cur); }
http://www.javascriptkit.com/dhtmltutors/csscursors.shtml
If you want it there permanently you should probably either have it included in the original thumnail, or add it using JavaScript rather than adding it to the HTML (this is purely style and shouldn't be in the content).
Let me know if you want help on the JavaScript side.
In CSS3, you can do the following:
.double-image {
background-image: url(images/img1.png), url(images/img2.png);
}
Took from Can I have multiple background images using CSS?
All we want is parent above child. This is how you do it.
You put img into span, set z-index & position for both elements, and extra display for span. Add hover to span so you can test it and you got it!
HTML:
<span><img src="/images/"></span>
CSS
span img {
position:relative;
z-index:-1;
}
span {
position:relative;
z-index:initial;
display:inline-block;
}
span:hover {
background-color:#000;
}
Unless you use the <img> tag, which displays an image by itself, you will not be able to achieve this with pure CSS alone. You will also need TWO HTML elements as well - one for each picture. This is because the only way you can make an element display a picture via CSS is with the background-image property, and every element can have only one background image. Which two elements you choose and how you position them is up to you. There are many ways how you can position one HTML element above another.
Here's a good technique to display an overlay image that is centered with a semi-transparent background over an image link:
HTML
<div class="image-container">
<a class="link" href="#" >
<img class="image" src="/img/thumbnail.png"/>
<span class="overlay-image"><img src="/img/overlay.png"></span>
</a>
</div>
CSS
div.image-container{
position: relative;
}
a.link{
text-decoration: none;
position: relative;
display: block;
}
a.link span.overlay-image{
visibility: hidden;
position: absolute;
left: 0px;
top: 0px;
bottom: 0px;
right: 0px;
background-color: rgba(0,0,0,0.2); /* black background with 20% alpha */
}
a.link span.overlay-image:before { /* create a full-height inline block pseudo=element */
content: ' ';
display: inline-block;
vertical-align: middle; /* vertical alignment of the inline element */
height: 100%;
}
a.link:hover span.overlay-image img{
display: inline-block;
vertical-align: middle;
}
a.link:hover span.overlay-image{
visibility: visible;
}
Here's a JQuery Technique with semi-transparent background.
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><img src="images/refferal_machine.png" width="100" alt="Refferal Machine By Matthew Spiel"></li>
<li><img src="images/space-juice.png" width="100" alt="Space Juice by Mat Helme"></li>
<li><img src="images/education.png" width="100" alt="Education by Chris Michel"></li>
<li><img src="images/copy_mcrepeatsalot.png" width="100" alt="Wanted: Copy McRepeatsalot by Chris Michel"></li>
<li><img src="images/sebastian.png" width="100" alt="Sebastian by Mat Helme"></li>
<li><img src="images/skill-polish.png" width="100" alt="Skill Polish by Chris Michel"></li>
<li><img src="images/chuck.png" width="100" alt="Chuck by Mat Helme"></li>
<li><img src="images/library.png" width="100" alt="Library by Tyson Rosage"></li>
<li><img src="images/boat.png" width="100" alt="Boat by Griffin Moore"></li>
<li><img src="images/illustrator_foundations.png" width="100" alt="Illustrator Foundations by Matthew Spiel"></li>
<li><img src="images/treehouse_shop.jpg" width="100" alt="Treehouse Shop by Eric Smith"></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>
CSS
/** Start Coding Here **/
#overlay {
background:rgba(0,0,0,0.7);
width:100%;
height:100%;
position:absolute;
top:0;
left:0;
display:none;
text-align:center;
}
#overlay img {
margin-top: 10%;
}
#overlay p {
color:white;
}
app.js
var $overlay = $('<div id="overlay"></div>');
var $image = $("<img>");
var $caption = $("<p></p>");
// 1. Capture the click event on a link to an image
$("#imageGallery a").click(function(event){
event.preventDefault();
var imageLocation = $(this).attr("href");
// 1.1 Show the overlay.
$overlay.show();
// 1.2 Update overlay with the image linked in the link
$image.attr("src", imageLocation);
// 1.3 Get child's alt attribute and set caption
var captionText = $(this).children("img").attr("alt");
$caption.text(captionText);
// 2. Add overlay
$("body").append($overlay);
// 2.1 An image to overlay
$overlay.append($image);
// 2.2 A caption to overlay
$overlay.append($caption);
});
//When overlay is clicked
$overlay.click(function(){
//Hide the overlay
$overlay.hide();
});
I have this minor issue where I want to insert a picture on my website. I manage to insert the picture but the problem comes when I want to insert an opacity into the code. I want the picture to become some kind of transparent when you hoover over it.
<a href="http://www.byggprojektoren.se" style="opacity: 1;"> <img
src="Image.jpg"> </a>
As it is right now it is not transparent when hoovering over with a mouse.
You can give it a :hover selector with css like this:
img:hover {
opacity:0,4;
}
Edit:
<html>
<head>
<style>
img:hover {
opacity:0,4;
}
</style>
</head>
<body>
<a href="http://www.byggprojektoren.se">
<img src="http://byggprojektoren.se/wp-content/uploads/2014/09/HomepagePic.jpg">
</a>
</body>
</html>
Use css instead of inline styles. You can also use css for the hover style, like this:
img {
opacity: 1;
}
img:hover {
opacity: 0.5;
}
<img src="picture.jpg" />
I have 3 images. When hovering one an image goes on top of the hovered one.
Here's my code:
HTML
<a class="toggle"><img src="" style="position:absolute"><img src=""></a>
<a class="toggle" style="margin-left:30px;margin-right:30px"><img src="" style="position:absolute"><img src=""></a>
<a class="toggle"><img src="" style="position:absolute"><img src=""></a>
CSS
a.toggle img:hover {
opacity:0.1;
filter:alpha(opacity=10); /* For IE8 and earlier */
}
Everything works fine with Firefox and Chrome.. Problem is with Internet Explorer (also IE 10). The middle image is positioned weirdly!
Check out the fiddle with IE to see the problem http://jsfiddle.net/6nebL/
How can I fix this in a clean way and without adding complexity to the code?
set a to inline-block:
a {
display: inline-block;
}
fiddle updated:
http://jsfiddle.net/6nebL/3/
Here, I've updated your CSS and HTML to be a bit more ... friendly. The CSS:
.toggle img:hover {
opacity:0.1;
filter:alpha(opacity=10); /* For IE8 and earlier */
}
.toggle {
display:inline-block;
vertical-align:middle;
width:150px;
position:relative;
margin:0 30px;
}
img {
position:absolute;
top:0;
left:0;
}
And HTML is just without the inline styles.
Here is the updated jsFiddle.
I want to overlay one image with another using CSS. An example of this is the first image (the background if you like) will be a thumbnail link of a product, with the link opening a lightbox / popup showing a larger version of the image.
On top of this linked image I would like an image of a magnifying glass, to show people that the image can be clicked to enlarge it (apparently this isn't obvious without the magnifying glass).
I just got done doing this exact thing in a project. The HTML side looked a bit like this:
<a href="[fullsize]" class="gallerypic" title="">
<img src="[thumbnail pic]" height="90" width="140" alt="[Gallery Photo]" class="pic" />
<span class="zoom-icon">
<img src="/images/misc/zoom.gif" width="32" height="32" alt="Zoom">
</span>
</a>
Then using CSS:
a.gallerypic{
width:140px;
text-decoration:none;
position:relative;
display:block;
border:1px solid #666;
padding:3px;
margin-right:5px;
float:left;
}
a.gallerypic span.zoom-icon{
visibility:hidden;
position:absolute;
left:40%;
top:35%;
filter:alpha(opacity=50);
-moz-opacity:0.5;
-khtml-opacity: 0.5;
opacity: 0.5;
}
a.gallerypic:hover span.zoom-icon{
visibility:visible;
}
I left a lot of the sample in there on the CSS so you can see how I decided to do the style. Note I lowered the opacity so you could see through the magnifying glass.
EDIT: To clarify for your example - you could ignore the visibility:hidden; and kill the :hover execution if you wanted, this was just the way I did it.
One technique, suggested by this article, would be to do this:
<img style="background:url(thumbnail1.jpg)" src="magnifying_glass.png" />
A simple way of doing that with CSS
only without modifying the content
with additional tags is shown here
(with code and example):
http://soukie.net/2009/08/20/typography-and-css/#example
This works, as long as the parent element is not using static positioning. Simply setting it to relative positioning does the trick. Also, IE <8 don't support the :before selector or content.
Edit:
Link above no longer works but is visible on the WayBack Machine:
https://web.archive.org/web/20120213121217/https://soukie.net/2009/08/20/typography-and-css/
Here is how I did it recently. Not perfect semantically, but gets the job done.
<div class="container" style="position: relative">
<img style="z-index: 32; left: 8px; position: relative;" alt="bottom image" src="images/bottom-image.jpg">
<div style="z-index: 100; left: 72px; position: absolute; top: 39px">
<img alt="top image" src="images/top-image.jpg"></div></div>
You might want to check out this tutorial:
http://www.webdesignerwall.com/tutorials/css-decorative-gallery/
In it the writer uses an empty span element to add an overlaying image. You can use jQuery to inject said span elements, if you'd like to keep your code as clean as possible. An example is also given in the aforementioned article.
Hope this helps!
-Dave
If you're only wanting the magnifing glass on hover then you can use
a:hover img { cursor: url(glass.cur); }
http://www.javascriptkit.com/dhtmltutors/csscursors.shtml
If you want it there permanently you should probably either have it included in the original thumnail, or add it using JavaScript rather than adding it to the HTML (this is purely style and shouldn't be in the content).
Let me know if you want help on the JavaScript side.
In CSS3, you can do the following:
.double-image {
background-image: url(images/img1.png), url(images/img2.png);
}
Took from Can I have multiple background images using CSS?
All we want is parent above child. This is how you do it.
You put img into span, set z-index & position for both elements, and extra display for span. Add hover to span so you can test it and you got it!
HTML:
<span><img src="/images/"></span>
CSS
span img {
position:relative;
z-index:-1;
}
span {
position:relative;
z-index:initial;
display:inline-block;
}
span:hover {
background-color:#000;
}
Unless you use the <img> tag, which displays an image by itself, you will not be able to achieve this with pure CSS alone. You will also need TWO HTML elements as well - one for each picture. This is because the only way you can make an element display a picture via CSS is with the background-image property, and every element can have only one background image. Which two elements you choose and how you position them is up to you. There are many ways how you can position one HTML element above another.
Here's a good technique to display an overlay image that is centered with a semi-transparent background over an image link:
HTML
<div class="image-container">
<a class="link" href="#" >
<img class="image" src="/img/thumbnail.png"/>
<span class="overlay-image"><img src="/img/overlay.png"></span>
</a>
</div>
CSS
div.image-container{
position: relative;
}
a.link{
text-decoration: none;
position: relative;
display: block;
}
a.link span.overlay-image{
visibility: hidden;
position: absolute;
left: 0px;
top: 0px;
bottom: 0px;
right: 0px;
background-color: rgba(0,0,0,0.2); /* black background with 20% alpha */
}
a.link span.overlay-image:before { /* create a full-height inline block pseudo=element */
content: ' ';
display: inline-block;
vertical-align: middle; /* vertical alignment of the inline element */
height: 100%;
}
a.link:hover span.overlay-image img{
display: inline-block;
vertical-align: middle;
}
a.link:hover span.overlay-image{
visibility: visible;
}
Here's a JQuery Technique with semi-transparent background.
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><img src="images/refferal_machine.png" width="100" alt="Refferal Machine By Matthew Spiel"></li>
<li><img src="images/space-juice.png" width="100" alt="Space Juice by Mat Helme"></li>
<li><img src="images/education.png" width="100" alt="Education by Chris Michel"></li>
<li><img src="images/copy_mcrepeatsalot.png" width="100" alt="Wanted: Copy McRepeatsalot by Chris Michel"></li>
<li><img src="images/sebastian.png" width="100" alt="Sebastian by Mat Helme"></li>
<li><img src="images/skill-polish.png" width="100" alt="Skill Polish by Chris Michel"></li>
<li><img src="images/chuck.png" width="100" alt="Chuck by Mat Helme"></li>
<li><img src="images/library.png" width="100" alt="Library by Tyson Rosage"></li>
<li><img src="images/boat.png" width="100" alt="Boat by Griffin Moore"></li>
<li><img src="images/illustrator_foundations.png" width="100" alt="Illustrator Foundations by Matthew Spiel"></li>
<li><img src="images/treehouse_shop.jpg" width="100" alt="Treehouse Shop by Eric Smith"></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>
CSS
/** Start Coding Here **/
#overlay {
background:rgba(0,0,0,0.7);
width:100%;
height:100%;
position:absolute;
top:0;
left:0;
display:none;
text-align:center;
}
#overlay img {
margin-top: 10%;
}
#overlay p {
color:white;
}
app.js
var $overlay = $('<div id="overlay"></div>');
var $image = $("<img>");
var $caption = $("<p></p>");
// 1. Capture the click event on a link to an image
$("#imageGallery a").click(function(event){
event.preventDefault();
var imageLocation = $(this).attr("href");
// 1.1 Show the overlay.
$overlay.show();
// 1.2 Update overlay with the image linked in the link
$image.attr("src", imageLocation);
// 1.3 Get child's alt attribute and set caption
var captionText = $(this).children("img").attr("alt");
$caption.text(captionText);
// 2. Add overlay
$("body").append($overlay);
// 2.1 An image to overlay
$overlay.append($image);
// 2.2 A caption to overlay
$overlay.append($caption);
});
//When overlay is clicked
$overlay.click(function(){
//Hide the overlay
$overlay.hide();
});