我的想法是,用定时器做高度变化,但是写出来之后发现效果并没有这么好啊,大家都有怎样的思路去实现呢function upDown(targetObj,max,min,speed) { var timer; var myStyle = targetObj.style; if ( myStyle.display == 'none' ){ myStyle.display = 'block'; var newHeight = parseInt(myStyle.height); clearInterval(timer); timer = setInterval(function(){ var newHeight = parseInt(myStyle.height); if ( parseInt(myStyle.height) == max ){ clearInterval(timer); }else{ myStyle.height = newHeight + speed + 'px'; } },1000/60); }else{ clearInterval(timer); timer = setInterval(function(){ var newHeight = parseInt(myStyle.height); if ( parseInt(myStyle.height) == min ){ clearInterval(timer); myStyle.display = 'none'; }else{ myStyle.height = newHeight - speed +'px'; } },1000/60); } }
添加回答
举报
0/150
提交
取消