2010-03-04 93 views
0

我有一个简单的js脚本来滚动图像的水平。不同平台上的Javascript

奇怪的是,它在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代码做一些事情cotiniously行为这样

+4

是啊,将行42从'var foo = bar;'换成'var foo = baz;'。真的吗?给我们一些代码,链接和/或资源来看看。我们不读头脑= P – anddoutoi 2010-03-04 14:04:38

+0

可以解释如果你显示一些代码/东西。 – 2010-03-04 14:04:53

+1

@anddoutoi:+1,但是我们中的一些人*读*头脑。我感到......讽刺...... – Robusto 2010-03-04 14:10:10

回答

0
<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> 

其实里面做一些事情cotiniously行为这种方式在视频管线

+0

你应该编辑你的问题,而不是提供这个答案。 – 2010-03-04 14:17:42

+0

赦免,第一次在这里... – Vetal 2010-03-04 14:18:53

1

可能是一些任何JavaScript代码。我猜测这台机器使用软件渲染,例如英特尔950或3100.视频驱动程序的差异可能会导致此问题。

+0

英特尔公司移动945GM – Vetal 2010-03-04 14:16:12