Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
591 views
in Technique[技术] by (71.8m points)

jquery - Get the offset of a hidden element

How can I get the coordinates of a hidden element? offset() doesn't support the use for hidden elements. Any hints?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If your element has had .hide() called on it, or if it's got display:none in css, the browser doesn't bother rendering it at all. In this case, the answer is not directly. In recent jQueries, you can't even get its width or height.

On the other hand, if you .show() an element, then .hide() it before an execution loop (an event firing through to when there's no more code to run for that event), the browser will be forced to relayout the page and you'll be able to get its offset between when it's shown and hidden, but it won't be forced to repaint, so your users won't see a blip, and you won't lose as much performance as you might think.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...