0

setTimeout在不同浏览器的快慢问题

Posted by 晴云孤魂 on 2011 年 06 月 28 日 in web development |

请测试以下代码:
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>无标题文档</title>
<style>
ul{list-style:none;height:20px;}
li{width:100px;background:#F30;margin:1px;float:left;text-align:center;}
</style>
</head>
<body>
<ul>
<li>0</li>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<button onclick=”start()”>start!</button>
<button onclick=”stop()”>stop!</button>
</body>
<script>
var li=document.getElementsByTagName(‘li’);
var ss=document.getElementsByTagName(‘li’)[0];
function start(){
var i=100;
var move=function(){
if(ss.m) clearTimeout(ss.m);
i+=5;
li[0].style.width=i+’px’;
if(i<1000) ss.m=setTimeout(move,1);
}
move();
}
function stop(){
if(ss.m) clearTimeout(ss.m)
}
</script>
</html>

下面代码中的框子在IE6中运行比较慢,而在谷歌、火狐浏览器中运行比较快,有没有统一快慢的办法?如何修改时间让它在IE6中运行快一点?

Copyright © 2011-2021 晴云孤魂's Blog All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.5, from BuyNowShop.com.

普人特福的博客cnzz&51la for wordpress,cnzz for wordpress,51la for wordpress