-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinal_showPic.js
70 lines (63 loc) · 2.5 KB
/
final_showPic.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
//结构样式行为彻底分离
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != "function")
window.onload = func;
else window.onload = function () {
oldonload();
func();
}
}
function insertAfter(newElement, targetElement) {
var parent = targetElement.parentNode;
if (parent.lastChild == targetElement)
parent.appendChild(newElement);
else parent.insertBefore(newElement, targetElement.nextSibling);
}
function preparePlaceholder() {
if (!document.createTextNode) return false;
if (!document.createElement) return false;
if (!document.getElementById) return false;
if (!document.getElementById("imagegallery")) return false;
var placeholder = document.createElement("img");
placeholder.setAttribute("id", "placeholder");
placeholder.setAttribute("src", "pic/来吧.gif");
placeholder.setAttribute("alt", "");
var gallery = document.getElementById("imagegallery");
insertAfter(placeholder, gallery);
var description = document.createElement("p");
description.setAttribute("id", "description");
var desctext = document.createTextNode("👆任选一个,看高清基艾艾弗图");
description.appendChild(desctext);
insertAfter(description, placeholder);
}
function prepareGallery() {
if (!document.getElementById) return false;
if (!document.getElementById("imagegallery")) return false;
if (!document.getElementsByTagName) return false;
var gallery = document.getElementById("imagegallery");
var links = gallery.getElementsByTagName("a");
for (var i = 0; i < links.length; i++) {
links[i].onclick = function () {
return !showPic(this);
}
}
}
function showPic(whichpic) {
var newsrc = whichpic.getAttribute("href");
var newdesc = whichpic.getAttribute("title") ? whichpic.getAttribute("title") : "找不到title属性";
if (!document.getElementById("placeholder")) return false;
var placeholder = document.getElementById("placeholder");
placeholder.setAttribute("src", newsrc);
if (!document.getElementById("description")) return false;
var description = document.getElementById("description");
if (description.firstChild.nodeType == 3)
description.firstChild.nodeValue = newdesc;
return true;
}
addLoadEvent(preparePlaceholder);
addLoadEvent(prepareGallery);
function reset() {
alert("不就是刷新页面吗,还要麻烦我来按。。。\n^(* ̄(oo) ̄)^");
location.reload();
}