var mh = 30;//最小高度
var step = 1;//每次变化的px量
var ms = 10;//每隔多久循环一次
function toggle(o){
if (!o.tid)o.tid = "_" + math.random() * 100;
if (!window.toggler)window.toggler = {};
if (!window.toggler[o.tid]){
window.toggler[o.tid]={
obj:o,
maxheight:o.offsetheight,
minheight:mh,
timer:null,
action:1
};
}
o.style.height = o.offsetheight + "px";
if (window.toggler[o.tid].timer)cleartimeout(window.toggler[o.tid].timer);
window.toggler[o.tid].action *= -1;
window.toggler[o.tid].timer = settimeout("anim('"+o.tid+"')",ms );
}
function anim(id){
var t = window.toggler[id];
var o = window.toggler[id].obj;
if (t.action < 0){
if (o.offsetheight = t.maxheight){
cleartimeout(t.timer);
return;
}
}
o.style.height = (parseint(o.style.height, 10) + t.action * step) + "px";
window.toggler[id].timer = settimeout("anim('"+id+"')",ms );
}
div.xx{border:solid 1px;overflow:hidden;}
div.xx h5{border:solid 1px;border-width:0 0 1px;padding:0;margin:0;height:30px;line-height:30px;cursor:pointer;background:#eee;}
点击我看"伸缩效果"
[ctrl+a 全选 注:如需引入外部js需刷新才能执行]