LoginSignup
0
2

More than 3 years have passed since last update.

jQueryでふわっとさせる(コピペ可)

Posted at

1.ふわっとさせたいHTMLの要素にクラスをつける

index.html
<div class="他クラスとも共存可 effect-fade">
//処理
<div>

2.CSSにふわっとさせる処理を書く

style.css
.effect-fade {
  opacity: 0;
  transform: translate(0, 100px); /* ふわっとさせる高さ */
  transition: all 1500ms; /* ふわっと仕切るまでにかかる時間 */
}
.effect-scroll {
  opacity: 1;
  transform: translate(0, 0);
}

3.Jqueryでふわっと詳細を書く

script.js
$(function () {
  $(window).scroll(function () {
    $(".effect-fade").each(function () {
      var elemPos = $(this).offset().top;
      var scroll = $(window).scrollTop();
      var windowHeight = $(window).height();
      if (scroll > elemPos - windowHeight) {
        $(this).addClass("effect-scroll");
      }
    });
  });
  jQuery(window).scroll();
});
0
2
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
2