首页 > JS 伸缩效果代码 (上下伸缩)

JS 伸缩效果代码 (上下伸缩)

ContractedBlock.gifExpandedBlockStart.gif代码
function toMinBox(obj) {

var speed = 10;

function strechH() {

var h = obj.offsetHeight;

if (h - speed <= 0) {

obj.style.display
= "none";

clearInterval(intervalID_Min);

}

else {

obj.style.height
= (h - speed) + "px";

}

}



intervalID_Min
= setInterval(strechH, 2);

}



function toMaxBox(obj) {

obj.style.display
= "block";

var speed = 10;

var originalHeight = !obj.childNodes[0].offsetHeight ? obj.getElementsByTagName("ul")[0].offsetHeight : obj.childNodes[0].offsetHeight;

function strechM() {

var h = obj.offsetHeight;

if (h >= originalHeight) {

clearInterval(intervalID_Max);

}

else {

obj.style.height
= (h + speed) + "px";

}

}



intervalID_Max
= setInterval(strechM, 2);

}

 

转载于:https://www.cnblogs.com/bndy/articles/1692164.html

更多相关: