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

スクロールで要素をフェードインで表示する

Last updated at Posted at 2019-11-18

プラグインが他のスクリプトとバッティングしたので・・・

スクロールして可視範囲に入ったら要素を表示するアニメーション【jQuery】
https://linkage-design.net/jquery-scroll-fadein

スクロール時の動きはjavascript書く。

script.js
jQuery(window).scroll(function () {

        //要素のフェードイン クラスfadeinがついたものに対して実行される。
        //ウインドウの表示範囲に入ったら、fadein-onクラスを付ける。
        $('.fadein').each(function(){
            var position = $(this).offset().top;
            var scroll = $(window).scrollTop();
            var windowHeight = $(window).height();
            if (scroll > position - windowHeight + 300){
              $(this).addClass('fadein-on');
            }
        });
    });

アニメーションの設定はcssに書く。

style.css
.fadein{
    opacity : 0;
    transition : all 0.7s;    
}

.fadein.fadein-on{
    opacity : 1;
}

とてもシンプルで、大変参考になりました。
ありがとうございました。

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