1
<script language="javascript" >
  var speed=25; //speed
  var num=0;
  var photos = document.getElementById('head_image');
  function scrollBG() {
    num++;
    photos.style.backgroundPosition="0"+num;
  }
  setInterval('scrollBG()',speed);
</script>

これが問題のサイトです: www.theorymarine.com

4

1 に答える 1

2

photos.style.backgroundPosition = "0" + num;

CSSの長さの単位が必要です。

photos.style.backgroundPosition= num+'px 0';

また、アニメーションの移動速度が「速度」やブラウザのパフォーマンスに依存しないように、時間に基づいてアニメーションを作成することもできます。例えば。:

<script type="text/javascript">
    var photos= document.getElementById('head_image');
    var begin= new Date().getTime();
    setInterval(function() {
        var x= Math.floor((new Date().getTime()-begin)/25);
        photos.style.backgroundPosition= x+'px 0';
    }, 25);
</script>
于 2009-09-23T20:54:00.490 に答える