往上縮的時(shí)候,一直在顫動(dòng),死活上不去,求指點(diǎn)
<style type="text/css">
?body{ margin:0; padding:0;}
?#pn{background:#090; width:500px; height:auto; margin:0 auto; text-align:center; display:block;}
?.content{width:500px; text-align:center; height:40px; background:#063; padding:10px; margin:0 auto;}
</style>
<script type="text/javascript">
?var h=0;
?function addh(){
if(h < 300){
h +=5;
? ? document.getElementById("pn").style.height=h+"px";
}
else { ??}
setTimeout("addh()",30);
}
window.onload=function showads(){
addh();
setTimeout("subh()",5000);
}
function subh(){
if(h>0){
h -=5;
document.getElementById("pn").style.height=h+"px";
}
else{}
setTimeout("subh()",300); ?
}
</script>
2015-09-05
你在else中需要return停止這個(gè)函數(shù)。否則你的h不滿(mǎn)足條件時(shí)你也會(huì)不斷延期執(zhí)行這個(gè)函數(shù)。自然就會(huì)不斷顫抖。
2015-09-05
你的時(shí)間間隔有點(diǎn)大,建議30毫秒