Skip to content

Instantly share code, notes, and snippets.

@furu
Created April 24, 2015 10:40
Show Gist options
  • Save furu/838ab496a4f1da90cbd4 to your computer and use it in GitHub Desktop.
Save furu/838ab496a4f1da90cbd4 to your computer and use it in GitHub Desktop.

ブラウザウィンドウのスクロール位置の取得

  • Window オブジェクト
    • pageXOffset プロパティ
    • pageYOffset プロパティ
    • scrollLeft プロパティ
    • scrollTop プロパティ

ドキュメントのルート要素 document.documentElement

ビューポートの大きさの取得

  • window.innerWidth
  • window.innerHeight

要素の大きさや位置の取得

要素のビューポート中での現在位置

  • getBoundingClientRect()

スクロール位置の設定

  • window.scrollTo()

  • window.scroll()

  • window.scrollBy()

  • window.scrollIntoView()

座標はドキュメント座標

<script src="js/jquery.min.js"></script>
<script>
  $(window).on('load', function() {
    console.log('window.pageYOffset: ' + window.pageYOffset);
    console.log('window.scrollY: ' + window.scrollY);
    console.log('document.documentElement.scrollTop: ' + document.documentElement.scrollTop);
    console.log('document.body.scrollTop: ' + document.body.scrollTop);
  });
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment