开发者

Getting offset of an object which is offscreen

开发者 https://www.devze.com 2023-01-26 02:41 出处:网络
I am trying to get offset position of an object which is not on screen. For example, I have a scroll which display two html pages, I want 开发者_如何学Pythonto draw lines on second page which is not o

I am trying to get offset position of an object which is not on screen. For example, I have a scroll which display two html pages, I want 开发者_如何学Pythonto draw lines on second page which is not on the curent screen. When i try to get offset it return me NaN.

Anyone have any idea how to get the positions of object which is not on screen?


I don't know of any problems getting the position of an off-screen object. You just need to make sure it is rendered. Usually, the problem is that your element is set to display:none, in which case you get NaN for its position. There are two solutions:

  • Make the element absolutely positioned (display: block) with top left very negative so it's offscreen
  • Just use 'visibility: hidden' instead. That forces it to calculate the dimensions even though it's not visible (since it takes up space)

Please post simplified code to show your problem if this does not solve your problem.

0

精彩评论

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

关注公众号