87,910
社区成员
发帖
与我相关
我的任务
分享
var object = {
speed: 3,
timer: null,
clickfun: function(id) {
var wrap = document.getElementById(id);
var aDiv = wrap.getElementsByTagName('div');
this.oA = wrap.getElementsByTagName('a')[0];
for (var i = 0; i < aDiv.length; i++) {
/*var minH=aDiv[i].offsetHeight;
var maxH=this.oA.offsetHeight*4+minH-1;*/
aDiv[i].onclick = function() {
object.time(this);
}
}
},
time: function(a) {
var _this = this;
var element = a.parentNode;
this.timer = setInterval(function() {
element.className == 'hidden' ? _this.open(a) : _this.close(a);
}, 5)
},
open: function(a) {
var element = a.parentNode;
var minH = a.offsetHeight;
var maxH = this.oA.offsetHeight * 4 + minH - 1;
var nowH = element.offsetHeight;
if (nowH < maxH) {
element.style.height = nowH + this.speed + 'px';
} else {
clearInterval(this.timer);
element.style.height = maxH;
this.setClassName(element, '');
}
},
close: function(a) {
var element = a.parentNode;
var minH = a.offsetHeight;
var nowH = element.offsetHeight;
if (nowH > minH) {
element.style.height = nowH - this.speed + 'px';
} else {
clearInterval(this.timer);
element.style.height = minH;
this.setClassName(element, 'hidden');
}
},
setClassName: function(obj, className) {
obj.className = className;
}
}
object.clickfun('wrap');