111
94

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

jQueryのoffset()を使う際の注意

Last updated at Posted at 2014-10-07

cssのzoomプロパティを使用した状態で、jQueryのoffsetメソッドを使用すると正しい値を取得することができない。
一方で、ネイティブのoffsetTopを使用すれば、cssにzoomを使用していても正しい値を取得することができる。
従って以下のようにコードを書き換えると良い。

jQuery:

var target = $( '#target' ).offset().top;

Native JavaScript:

var target = $( '#target' ).get( 0 ).offsetTop
111
94
5

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
111
94

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?