LoginSignup
0
0

More than 1 year has passed since last update.

ある程度スクロールするとじわっと表示させる

Last updated at Posted at 2021-06-11

やる事

スクロールをしていって、要素がスクリーンのある程度に来るとじわっと表示させる。

方法

html
<section class="fadein">
 <!--何かしらの要素を入れる-->
</section>
javascript
$(function(){
  $(window).scroll(function (){
    $(".fadein").each(function(){
      let imgPos = $(this).offset().top;
      let scroll = $(window).scrollTop();
      let windowHeight = $(window).height();
      if (scroll > imgPos - windowHeight + 250){ //ここの数値を変えて表示させる箇所を変更する
        $(this).addClass("fadein_scroll");
      } else {
        $(this).removeClass("fadein_scroll");
      }
    });
  });
});
css
.fadein {
    opacity: 0;
    -webkit-transition: all 1s;
    -moz-transition: all 1s;
    -o-transition: all 1s;
    -ms-transition: all 1s;
    transition: all 1s;
    }

.fadein_scroll {
    opacity : 1;
    }
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