-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
37 lines (27 loc) · 807 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
//Image Modal Script
var dvContent = document.getElementById("dvContent");
var dvModal = document.getElementById("dvModal");
dvModal.setAttribute("onclick", "CloseModal();");
SetAllImages();
function SetAllImages(){
var images = document.getElementsByTagName("img");
for(var i = 0; i < images.length; i++){
var img = images[i].getAttribute("src");
images[i].setAttribute("onclick", "OpenModal('"+img+"', '"+images[i].alt+"')");
}
}
function OpenModal(src, alt){
dvContent.innerHTML = "";
var img = document.createElement("img");
img.src = src;
img.alt = alt;
var p = document.createElement("p");
p.innerText = alt;
dvContent.appendChild(img);
dvContent.appendChild(p);
dvModal.style.display = "block";
}
function CloseModal(){
dvModal.style.display = "none";
}
//Image Modal Script End