开发者

Bind the position of an element to another element's position

开发者 https://www.devze.com 2023-02-19 15:46 出处:网络
Is there any way in jQuery to make an element stay at the same position as another element? Say there is a textbox and a <span>. How would one let the <span> always overlap the textbox, i

Is there any way in jQuery to make an element stay at the same position as another element?

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.

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.

Thanks for any tips.


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" />.


If you control the times when the textbox moves, you can also trigger the movement of the span. If not, then I'm unaware of any events that would work better than your setInterval idea.

0

精彩评论

暂无评论...
验证码 换一张
取 消