views:

185

answers:

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>

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

+2  A: 

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>
bobince
i had to edit line 5 of your code to get it to work (moving the /25 to a new line) but this did the trick. Thanks
Stoob
Oops! There was a missing bracket. Fixed, cheers
bobince