Make background position variable

前端 未结 2 485
星月不相逢
星月不相逢 2021-01-07 03:10

I\'m using this code...

document.getElementById(\'a1\').style.backgroundPosition = \'0px 0px\';

and it works fine but is there anyway to

相关标签:
2条回答
  • 2021-01-07 03:34

    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';
    
    0 讨论(0)
  • 2021-01-07 03:45
    var bgPos = '20px';
    document.getElementById('a1').style.backgroundPosition = '0px ' + bgPos;
    
    0 讨论(0)
提交回复
热议问题