1 $(document
).ready(function() {
2 $(".lightbox").click(function() {
3 overlayLink
= $(this).attr("href"); //Getting the link for the media
4 window
.startOverlay(overlayLink
);
9 function startOverlay(overlayLink
) {
11 // Adding elements to the page
13 .append('<div class="overlay"></div><div class="box"></div>')
15 "overflow-y": "hidden"
18 // To create the lightbox effect
19 $(".container").animate({
23 var imgWidth
= $(".box img").width();
24 var imgHeight
= $(".box img").height();
26 //adding the image to the box
28 $(".box").html('<img height=100% width=100% src="' + overlayLink
+ '" alt="" />');
30 $(".box img").load(function() {
31 var imgWidth
= $(".box img").width();
32 var imgHeight
= $(".box img").height();
33 if (imgHeight
> screen
.height
- 170) imgHeight
= screen
.height
- 170;
34 if (imgWidth
> screen
.width
- 300) imgWidth
= screen
.width
- 300;
37 "position": "absolute",
40 "height": imgHeight
+ 10,
41 "width": imgWidth
+ 10,
42 "border": "5px solid white",
43 "margin-top": -(imgHeight
/ 2),
44 "margin-left": -(imgWidth
/ 2) //to position it in the middle
51 window
.closeOverlay();
55 function closeOverlay() {
56 // allow users to be able to close the lightbox
57 $(".overlay").click(function() {
58 $(".box, .overlay").animate({
60 }, 200, "linear", function() {
61 $(".box, .overlay").remove();
63 $(".container").animate({
67 "overflow-y": "scroll"