0

I seem to have trouble with this line:

back_x += 1;
back_y += 10;           

document.getElementById('body_id').style.backgroundPosition =  back_x + 'px ' + back_y + 'px';

.css file

body
{   
   background: #000;    
background-image:url('image.jpg');
background-repeat:repeat;
font-family: Helvetica, sans-serif; font-size: 18px; line-height: 24px;
background-attachment:fixed;
}

<BODY id = "body_id"; >

Basically I'm trying to use Javascript to update the background image position which works only once within a loop and and doesn't work again thereafter. Everything else on the page runs fine. Could it be the string is not concatenated properly?

EDIT: After a couple of minutes my page runs fine then all JavaScript functions cease to work! =(

pandoragami
  • 5,387
  • 15
  • 68
  • 116

1 Answers1

1

I don't see any problem on your code.

But you can maybe test this:

function updatePositionBackground(x, y) {
   document.body.style.backgroundPosition = x + "px " + y+ "px";
}

A do a sample: http://jsfiddle.net/RN8mB/

You can see that the background position is correctly updated.

Thomas Durieux
  • 466
  • 2
  • 5
  • It does work but it only seems to update the background once and never again. Everything in my Javascript loop runs like before but the background position doesn't update. – pandoragami Mar 06 '13 at 23:21
  • It isn't the code that you given to us. Please share the rest of your code if you would like some help. – Thomas Durieux Mar 06 '13 at 23:23
  • The code I showed is most of the loop. There isn't much more to it but I'll post it soon. – pandoragami Mar 06 '13 at 23:27
  • Nevermind, it works now. I just realized that I put `var back_x = 0; var back_y = 0;` within the loop with the background position update! – pandoragami Mar 06 '13 at 23:31