JS实现简单的顶部定时关闭层效果
内容摘要
复制代码 代码如下: <script type="text/javascript"> var time = 300; var h = 0; function addCount() { if(time>0) { time--; h = h+5; } else { return; } if(h>300) /
文章正文
复制代码 代码如下:
<script type="text/javascript">
var time = 300;
var h = 0;
function addCount()
{
if(time>0)
{
time--;
h = h+5;
}
else
{
return;
}
if(h>300) //高度
{
return;
}
document.getElementById("ads").style.display = "";
document.getElementById("ads").style.height = h+"px";
setTimeout("addCount()",30);
}
window.onload = function showAds()
{
addCount();
setTimeout("noneAds()",7000); //停留时间自己调了
}
var T = 300;
var N = 300; //高度
function noneAds()
{
if(T>0)
{
T--;
N = N-5;
}
else
{
return;
}
if(N<0)
{
document.getElementById("ads").style.display = "none";
return;
}
document.getElementById("ads").style.height = N+"px";
setTimeout("noneAds()",30);
}
</script>
复制代码 代码如下:
<div style="MARGIN: 0px auto; WIDTH: 900px; BACKGROUND: #369; HEIGHT: 300px; COLOR: #fff" id="ads">phpstudy_www.phpstudy.net</div>
代码注释