Html CSS/Javascript如何在Firefox中制作这个背景位置电影,就像在IE7+;中一样;? 无功转速=25//速度 var num=0; var photos=document.getElementById('head_image'); 函数scrollBG(){ num++; 照片.style.backgroundPosition=“0”+num; } 设置间隔('scrollBG()',速度);

Html CSS/Javascript如何在Firefox中制作这个背景位置电影,就像在IE7+;中一样;? 无功转速=25//速度 var num=0; var photos=document.getElementById('head_image'); 函数scrollBG(){ num++; 照片.style.backgroundPosition=“0”+num; } 设置间隔('scrollBG()',速度);,html,css,background-position,Html,Css,Background Position,这是有问题的网站:www.theoreymarine.com 照片.style.backgroundPosition=“0”+num CSS长度需要一个单位 <script language="javascript" > var speed=25; //speed var num=0; var photos = document.getElementById('head_image'); function scrollBG() { num++; pho

这是有问题的网站:www.theoreymarine.com

照片.style.backgroundPosition=“0”+num

CSS长度需要一个单位

<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>
您可能还希望动画基于时间,以便其移动速率不依赖于“速度”或浏览器性能。例如:

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

var photos=document.getElementById('head_image');
var begin=new Date().getTime();
setInterval(函数(){
var x=Math.floor((new Date().getTime()-begin)/25);
photos.style.backgroundPosition=x+'px 0';
}, 25);

我不得不编辑代码的第5行以使其正常工作(将/25移到新行),但这成功了。谢谢
<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>