0
0

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 3 years have passed since last update.

JavaScript : ページの最下部に来た時にイベントを起こす

Posted at

スクロールがページの一番下に到達したことをJavaScriptで拾うには以下のようにする。

$(window).on('scroll', function () {
  var doch = $(document).innerHeight(); //ページ全体の高さ
  var winh = $(window).innerHeight(); //ウィンドウの高さ
  var bottom = doch - winh; //ページ全体の高さ - ウィンドウの高さ = ページの最下部位置
  if (bottom <= $(window).scrollTop()) {
    //一番下までスクロールした時に実行
    console.log("最底辺!");
  }
});

一番下まで行かずとも「ページの80%」で動作させたいなら、5行目の if 文を以下のようにする。

if (bottom * 0.8 <= $(window).scrollTop()) {
0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?