0
1

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.

inview.jsを用いた要素が順番に表示されるアニメーション

Last updated at Posted at 2018-12-19

備忘録としてメモ。

要素が順に表示されるアニメーションを「inview.js」を用いて実装しました。
※jQuery使用。

以下がソース。

order.html 
         <ul class="box js-inview" id="box01">
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
        </ul>
        <ul class="box js-inview" id="box02">
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
        </ul>
        <ul class="box js-inview" id="box03">
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
          <li></li>
        </ul>
order.scss 
.box {
  width: 100%;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  li {
    width: 23%;
    height: 200px;
    list-style: none;
    margin-bottom: 20px;
    // 最初は見えないようにしておく
    opacity: 0;
  }

  &+ .box {
    margin-top: 300px;
  }
}

.js-inview {
  .js-showed {
    animation: fadeIn01 .9s ease-out forwards;
  }
}

@keyframes fadeIn01 {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

#box01 {
  li {
    background: rgb(107, 230, 55);
  }
}

#box02 {
  li {
    background: rgb(230, 228, 55);
  }
}

#box03 {
  li {
    background: rgb(230, 160, 55);
  }
}

order.js 
$(function() {
  $('.js-inview').on('inview', function(event, isInView) {
    if (isInView) {
      $(this).find('li').each(function(i) {
        $(this).delay(100 * i).queue(function() {
          $(this).addClass('js-showed ').dequeue();
        });
      });
    }
  });
});

簡単に説明すると、

1、要素「.js-inview」が画面内へ入ったら
2、その入り込んだ要素「.js-inview」の中から「li」を探し、
3、その「li」に対し繰り返し「js-showed」クラスを与える。

最初は「opacity:0」で隠しておき、keyframeでアニメーションを付与しています。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?