forked from Okami-/Vanilla-JS-LightBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
37 lines (29 loc) · 960 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function expandPhoto() {
// create overlay and append to page
var overlay = document.createElement("div");
overlay.setAttribute("id","overlay");
overlay.setAttribute("class", "overlay");
document.body.appendChild(overlay);
// create image and append to page
var img = document.createElement("img");
img.style.width = "30%";
img.setAttribute("id","img");
img.src = this.getAttribute("data-larger");
img.setAttribute("class","overlayimg");
// click to restore page
img.onclick=restore;
document.body.appendChild(img);
}
// restore page to normal
function restore() {
document.body.removeChild(document.getElementById("overlay"));
document.body.removeChild(document.getElementById("img"));
}
window.onload=function() {
var imgs = document.getElementsByTagName("img");
imgs[0].focus();
for (var i = 0; i < imgs.length; i++) {
imgs[i].onclick=expandPhoto;
imgs[i].onkeydown=expandPhoto;
}
}