我试过了
document.getElementById('first').style.top = document.getElementById('second')
.style.top + 80;
但这似乎行不通。如何实现?
最佳答案
是的,您可以通过解析位置并使用新值和单位部分字符串重建字符串来做到这一点。
var match = document.getElementById('second').style.top.match(^(\d+(?:\.\d+)?)(.*)$);
document.getElementById('first').style.top = (parseFloat(match[1]) + 80) + match[2];
关于javascript - 一个元素的位置是否可以表示为另一个加号像素的位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41316412/