-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateList.js
97 lines (97 loc) · 4.1 KB
/
CreateList.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
92
93
94
95
96
97
function CreateList() {
this.oWrap = document.createElement("div");
this.copyright = document.createElement("div");
this.initialize.apply(this, arguments);
this.click.call(this);
}
CreateList.prototype = {
initialize: function(aData) {
var oDl, oElem, project, i;
while(aData[0]) {
oDl = document.createElement("dl");
project = aData[0].project;
for(i = 0; i < project.length; i++) {
if(project[i].href) {
oElem = document.createElement("dd");
oElem.innerHTML = i + ") <a href=\"" + project[i].href + "\" target=\"_blank\">" + project[i].text + "</a>"
}
else {
oElem = document.createElement("dt");
oElem.innerHTML = project[i].text + " (" + (project.length - 1) + ")"
}
oDl.appendChild(oElem);
oDl.style.height = "31px"
}
this.oWrap.appendChild(oDl);
aData.shift()
}
this.oWrap.id = "wrap";
this.copyright.id = "copyright";
this.copyright.innerHTML = "\u539f\u751f javascript \u5b66\u4e60, QQ:756148873, By Arete";
document.body.appendChild(this.oWrap);
document.body.appendChild(this.copyright)
},
click: function() {
var that = this;
this.oWrap.onclick = function(event) {
var oEv, oTarget, oParent, i;
oEv = event || window.event;
oTarget = oEv.target || oEv.srcElement;
oParent = oTarget.parentElement || oTarget.parentNode;
oParent.height = function() {
var iHeight = 0;
for(i = 0;i < oParent.children.length; i++) iHeight += oParent.children[i].offsetHeight;
return iHeight
}();
if(oTarget.tagName.toUpperCase() == "DT") {
var aSiblings = that.siblings(oParent), count, i;
for(count = i = 0; i < aSiblings.length; i++) {
that.startMove(aSiblings[i], oTarget.offsetHeight, "buffer", function() {
this.children[0].className = "";
if(++count == aSiblings.length) {
if(oParent.offsetHeight == oTarget.offsetHeight) {
oTarget.className = "current";
that.startMove(oParent, oParent.height, "flex")
}
else {
that.startMove(oParent, oTarget.offsetHeight, "buffer", function() {
oTarget.className = ""
})
}
}
})
}
}
}
},
startMove: function(obj, iTarget, type, callback) {
var that = this;
clearInterval(obj.timer);
obj.iSpeed = 0;
obj.timer = setInterval(function() {
that[type].call(that, obj, iTarget, callback)
}, 30)
},
buffer: function(obj, iTarget, callback) {
obj.iSpeed = (iTarget - obj.offsetHeight) / 5;
obj.iSpeed = obj.iSpeed > 0 ? Math.ceil(obj.iSpeed) : Math.floor(obj.iSpeed);
obj.offsetHeight == iTarget ? (clearInterval(obj.timer), callback && callback.call(obj)) : obj.style.height = obj.offsetHeight + obj.iSpeed + "px"
},
flex: function(obj, iTarget, callback) {
obj.iSpeed += (iTarget - obj.offsetHeight) / 6;
obj.iSpeed *= 0.75;
if(Math.abs(iTarget - obj.offsetHeight) <= 1 && Math.abs(obj.iSpeed) <= 1) {
clearInterval(obj.timer);
obj.style.height = iTarget + "px";
callback && callback.call(obj)
}
else {
obj.style.height = obj.offsetHeight + obj.iSpeed + "px"
}
},
siblings: function(element) {
var aTmp = [], oParent = element.parentElement || element.parentNode, i;
for(i = 0; i < oParent.children.length; i++) element != oParent.children[i] && aTmp.push(oParent.children[i]);
return aTmp
}
};