3
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?

【jQuery】特定の要素までスクロールしたときに要素を表示

Last updated at Posted at 2020-07-09

はじめに

Webサイトのホームページでよくあるスクロールしたときに要素がフワッと表示されるアニメーションをjQueryで実装するにはどうしたら良いかを復習。

アニメーションのロジック

実際にスクロールした量と画面のトップから特定要素までのオフセットをjQueryで取得。
「スクロールした量 > 特定の要素までのオフセット」のときにaddClassやfadeInなどでアニメーションを実行。
最後にブラウザの高さを取得すればアニメーション完成。

ソースコード

index.js
$(function(){
 var offset = $('特定の要素').offset().top;
 var height = $(window).height();

 $(window).scroll(function () {
   if ($(this).scrollTop() > offset - height) {
      // アニメーションを実行
    } 
 });
}
3
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
3
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?