-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray-script.js
93 lines (76 loc) · 2.76 KB
/
array-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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
var imgArray = new Array();
imgArray[0] = "pic/grid-img/beijing.jpg";
imgArray[1] = "pic/grid-img/bnaff.jpeg";
imgArray[2] = "pic/grid-img/leshan.jpg";
imgArray[3] = "pic/grid-img/taishan.jpg";
var imgDescri = new Array();
imgDescri[0] = "num 1 image:Beijing";
imgDescri[1] = "num 2 image: Bnaff";
imgDescri[2] = "num 3 image:LeShan";
imgDescri[3] = "num 4 image:TaiShan";
var imgLink = new Array();
imgLink[0] = "https://en.wikipedia.org/wiki/Great_Wall_of_China";
imgLink[1] = "https://www.pc.gc.ca/en/pn-np/ab/banff/index";
imgLink[2] = "http://www.leshandafo.com/";
imgLink[3] = "https://whc.unesco.org/en/list/437";
var position = document.getElementById("main-banner");
console.log(position);
tbl = document.createElement("table");
tbl.style.tableLayout = "fixed";
tbl.style.width = '80%';
tbl.style.textAlign = "center";
tbl.style.marginLeft = "auto";
tbl.style.marginRight = "auto";
tbl.style.border="1px solid black";
tbl.style.borderCollapse="collapse";
tbl.setAttribute("id","picTable");
tr = tbl.insertRow();
th = document.createElement("th");
th.appendChild(document.createTextNode("Image"));
tr.appendChild(th);
th.style.border="1px solid black";
th.style.borderCollapse="collapse";
th = document.createElement("th");
th.appendChild(document.createTextNode("Description"));
tr.appendChild(th);
for (var i = 0; i <imgArray.length; i++) {
var tr = tbl.insertRow();
var td = tr.insertCell();
td.style.border="1px solid black";
td.style.borderCollapse="collapse";
if (i < imgArray.length) {
img = document.createElement("img");
img.setAttribute("src", imgArray[i]);
img.addEventListener("mouseover", showDescript);
img.addEventListener("click", showWebsite);
img.style.width = "200px";
img.style.cursor = "pointer";
td.appendChild(img);
}
if (i == 0) {
var td = tr.insertCell();
td.style.border="1px solid black";
td.setAttribute('rowSpan', imgArray.length);
td.appendChild(document.createTextNode("Click One Image For Description"));
td.style.fontSize = "2em";
}
}
position.appendChild(tbl);
function showDescript() {
var currentImage = event.currentTarget;
//get rows then get rowIndex which is ID
var rowNumber = currentImage.parentNode.parentNode.rowIndex;
console.log(currentImage.parentNode.parentNode);
console.log(rowNumber);
//get content from particular table positon
tbl.rows[1].cells[1].innerHTML = imgDescri[rowNumber - 1];
}
function showWebsite() {
var currentImage = event.currentTarget;
//get rows then get rowIndex which is ID
var rowNumber = currentImage.parentNode.parentNode.rowIndex;
var myWindow = window.open(imgLink[rowNumber - 1]);
setTimeout(function () {
myWindow.close();
}, 2000);
}