【问题标题】:How do you get the current viewport position of a DOM element using Google's Closure library?如何使用 Google 的 Closure 库获取 DOM 元素的当前视口位置?
【发布时间】:2012-11-01 23:47:07
【问题描述】:

我正在为一个项目使用 Google 的闭包库,并希望找到给定元素在页面上的位置。基本上我想做 Quirksmode findPos() 所做的事情:

http://www.quirksmode.org/js/findpos.html

我查看了 Google 的定位文档:

http://closure-library.googlecode.com/svn/docs/namespace_goog_positioning.html

...但是我找不到与获取元素当前位置相关的任何内容。 库是否提供了解决方案,还是我应该求助于原生 javascript 来处理这个问题?

【问题讨论】:

  • 为什么不是 jQuery 的 .position 或 .offset 函数?看起来像你所需要的
  • 因为我正在做的项目是使用闭包而不是 jQuery。

标签: javascript positioning google-closure google-closure-library


【解决方案1】:

您要查找的功能位于goog.style,我很确定goog.style.getPageOffset 就是您想要的。

【讨论】:

  • 谢谢!这正是我想要的。
猜你喜欢
  • 1970-01-01
  • 2017-10-12
  • 2016-08-02
  • 2016-05-08
  • 1970-01-01
  • 2010-11-23
  • 1970-01-01
  • 2020-03-28
  • 1970-01-01
相关资源
最近更新 更多