使背景位置可变 [英] Make background position variable
本文介绍了使背景位置可变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码...
I'm using this code...
document.getElementById('a1').style.backgroundPosition = '0px 0px';
它可以正常工作,但是仍然可以使用javascript来生成定位变量吗?
and it works fine but is there anyway to make the positioning variable with javascript?
像这样...
document.getElementById('a1').style.backgroundPosition = '0px VariableHere';
推荐答案
由于背景位置是字符串,因此您只需将其值串联即可.
Since the background position is a string, you can just concatenate your value in.
例如:
var yValue = 20;
document.getElementById('a1').style.backgroundPosition = '0px ' + yValue + 'px';
这篇关于使背景位置可变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文