views:

53

answers:

2

I've got a simple js script that scrolls image horizontaly.

the strange thing is, it loads CPU up to 100% on windows, while on linux the CPU load rarely reaches 20% on the same computer.

I've tested this in firefox, chrome and opera on both platforms — results are practically the same.

Can someone explain what's going on?

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

in fact, any javascript code which does something cotiniously behaves that way

A: 
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); }

in fact, any javascript code which does something cotiniously behaves that way

Vetal
You should edit your question instead of providing this as an answer.
Benjamin Oakes
pardon, first time here...
Vetal
+1  A: 

Probably something in the video pipeline. I'm going to guess that this machine uses software rendering, e.g. an Intel 950 or 3100. Differences in the video driver could cause this.

Ignacio Vazquez-Abrams
Intel Corporation Mobile 945GM
Vetal