Reputation: 817
I'm using this code...
document.getElementById('a1').style.backgroundPosition = '0px 0px';
and it works fine but is there anyway to make the positioning variable with javascript?
like so...
document.getElementById('a1').style.backgroundPosition = '0px VariableHere';
Upvotes: 2
Views: 8830
Reputation: 78006
var bgPos = '20px';
document.getElementById('a1').style.backgroundPosition = '0px ' + bgPos;
Upvotes: 0
Reputation: 26530
Since the background position is a string, you can just concatenate your value in.
For example:
var yValue = 20;
document.getElementById('a1').style.backgroundPosition = '0px ' + yValue + 'px';
Upvotes: 7