将一个元素的位置绑定到另一个元素的位置 [英] Bind the position of an element to another element's position
问题描述
jQuery中有什么方法可以使一个元素与另一个元素保持相同的位置?
Is there any way in jQuery to make an element stay at the same position as another element?
说有一个文本框和一个<span>
.如何让<span>
始终与文本框重叠,即将其绑定在同一位置?另外,当文本框由于任何原因移动时,我也希望<span>
保持不变.
Say there is a textbox and a <span>
. How would one let the <span>
always overlap the textbox, i.e. have it bound at the same position? Also, when the textbox is moving for any reason, I'd like to have the <span>
go along.
我在想一个setInterval
,它每秒检查一次特定次数并适当地移动<span>
,但是在我看来这既昂贵又是一个肮脏的把戏.
I was thinking of a setInterval
which checks a certain number of times a second and move the <span>
appropriately, however this is both expensive and a dirty trick in my opinion.
感谢任何提示.
推荐答案
除非我对您的问题有误解,否则可以将<span>
和<input type="text" />
放在同一父容器(例如<div>
)中,然后移动<div>
而不是<input type="text" />
.
Unless I am misunderstanding your question, you could put the <span>
and the <input type="text" />
in the same parent container, such as a <div>
, then move the <div>
instead of the <input type="text" />
.
这篇关于将一个元素的位置绑定到另一个元素的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!