Search code examples
htmlcssbackground-position

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


<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


Solution

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