【发布时间】:2023-03-27 13:27:01
【问题描述】:
我有一个简单的 js 脚本,可以水平滚动图像。
奇怪的是,它在 windows 上的 CPU 负载高达 100%,而在 linux 上,同一台计算机上的 CPU 负载很少达到 20%。
我已经在两个平台上的 Firefox、chrome 和 opera 中对此进行了测试——结果几乎相同。
有人可以解释发生了什么吗?
<script>
var scrllTmr;
window.onload = function(){
//set style
document.getElementById('scroll').style.overflow = 'hidden';
document.getElementById('scrollme').style.float = 'left';
document.getElementById('scrollme').style.position = 'relative';
//get canvas
cw = parseInt(document.getElementById('scroll').offsetWidth);
w = parseInt(document.getElementById('scrollme').offsetWidth);
//start scroll
lft = -2101;
document.getElementById('scrollme').style.left = lft + "px";
scrollStep(cw,w,lft);
}
function scrollStep(cw,w,lft){
//calc and do step
if(lft == w * -1)
lft = cw + w;
document.getElementById('scrollme').style.left = lft + "px";
//wait and do next...
if(scrllTmr)
clearTimeout(scrllTmr);
scrllTmr = setTimeout('scrollStep(cw,w,' + (lft - 1) + ')',10);
}
</script>
事实上,任何执行某些操作的 javascript 代码都会以这种方式运行
【问题讨论】:
-
是的,将第 42 行从
var foo = bar;更改为var foo = baz;。严重地?给我们一些代码、链接和/或资源来查看。我们不读心=P -
如果你显示一些代码/东西可以解释。
-
@anddoutoi:+1,但我们中的一些人确实读心术。我有一种……讽刺的感觉……
标签: javascript windows linux