CSS/Javascript How do I make this background-position movie in Firefox like it does in IE7+?

你离开我真会死。 提交于 2019-12-11 06:15:36

问题


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

This is the site in question: www.theorymarine.com


回答1:


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

You need a unit for CSS lengths.

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

You might also prefer to base your animation on the time, so that the rate it moves is not dependent on ‘speed’ or browser performance. eg.:

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


来源:https://stackoverflow.com/questions/1468272/css-javascript-how-do-i-make-this-background-position-movie-in-firefox-like-it-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!