CSS / Javascript如何在Firefox中制作这样的背景位置电影,就像在IE7 +中一样?

时间:2009-09-23 20:09:05

标签: html css background-position

<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

1 个答案:

答案 0 :(得分: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>