怎样用JS定时器让多个指定DIV在页面加载后依次出现? 10
就是先先display:none,再用定时器修改display:block来实现,求代码,小白不懂...
就是先先display:none,再用定时器修改display:block来实现,求代码,小白不懂
展开
1个回答
展开全部
<!DOCTYPE HTML>
<html>
<head>
<meta charset=UTF-8 />
<title>recursion</title>
<style type="text/css">
</style>
<script type="text/javascript">
var interval = null, index = 0;
window.onload = function ()
{
for ( var i = 0; i < 10; i++)
{
var div = document.createElement ('div');
div.style.position = 'absolute';
div.style.border = '1px solid black';
div.style.width = '100px';
div.style.height = '100px';
div.style.top = 110 * i + 'px';
div.style.display = 'none';
var txt = document.createTextNode(i + 1);
div.appendChild(txt);
document.body.appendChild (div);
}
var div = document.getElementsByTagName ('div');
var temp = !/.*chrome.*/i.test(navigator.userAgent) ? document.documentElement:document.body;
interval = setInterval (function ()
{
if (index == div.length)
{
clearInterval(interval);
interval = null;
return false;
}
div[index++].style.display = 'block';
temp.scrollTop += 110;
}, 1000);
}
</script>
</head>
<body>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询