<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css" rel="stylesheet">
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous">
</script>
<style>@charset "utf-8";

/*========= レイアウトのためのCSS ===============*/

body {
  vertical-align: middle;
  text-align: center;
  width: 100%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  background-image: linear-gradient(
    100.6deg,
    rgba(218, 185, 252, 1) 22%,
    rgba(125, 89, 252, 1) 80%
  );
}

.flex {
  display: flex;
  flex-wrap: wrap;
  margin-top: 30px;
}

.box {
  width: 200px;
  padding: 20px;
  margin: 20px 20px;
  color: #333;
  box-sizing: border-box;
  white-space: nowrap;

  background-color: rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(6.5px);
  -webkit-backdrop-filter: blur(6.5px);

  box-shadow: 0px 6px 15px 0px rgba(142, 142, 142, 0.19);
  -webkit-box-shadow: 0px 6px 15px 0px rgba(142, 142, 142, 0.19);

  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 12px;
  -webkit-border-radius: 12px;
}

li {
  list-style: none;
}

/*==================================================
スタート時は要素自体を透過0にするためのopacity:0;を指定する
===================================*/

.box {
  opacity: 0;
}

/*==================================================
ふわっ
===================================*/

.fadeUp {
  animation-name: fadeUpAnime;
  animation-duration: 0.5s;
  animation-fill-mode: forwards;
  opacity: 0;
}

@keyframes fadeUpAnime {
  from {
    opacity: 0;
    transform: translateY(100px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}</style>
</head>
<body>
<body>
<ul class="flex delayScroll">
<li class="box">
<img src="http://localhost:10072/wp-content/uploads/demos/_assets/webnavi1.png" width="100" />
<br>順番に表示 ふわっ</li>
<li class="box">
<img src="http://localhost:10072/wp-content/uploads/demos/_assets/webnavi1.png" width="100" />
<br>順番に表示 ふわっ</li>
<li class="box">
<img src="http://localhost:10072/wp-content/uploads/demos/_assets/webnavi1.png" width="100" />
<br>順番に表示 ふわっ</li>
</ul>
<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓スクロール後に順番に出る<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓<br>↓
  <!--スクロールしてふわっ-->
<ul class="flex delayScroll">
<li class="box">
<img src="http://localhost:10072/wp-content/uploads/demos/_assets/webnavi1.png" width="100" />
<br>順番に表示 ふわっ</li>
<li class="box">
<img src="http://localhost:10072/wp-content/uploads/demos/_assets/webnavi1.png" width="100" />
<br>順番に表示 ふわっ</li>
<li class="box">
<img src="http://localhost:10072/wp-content/uploads/demos/_assets/webnavi1.png" width="100" />
<br>順番に表示 ふわっ</li>
</ul>
<script>function delayScrollAnime() {
  var time = 0.2; //遅延時間を増やす秒数の値
  var value = time;
  $(".delayScroll").each(function () {
    var parent = this; //親要素を取得
    var elemPos = $(this).offset().top; //要素の位置まで来たら
    var scroll = $(window).scrollTop(); //スクロール値を取得
    var windowHeight = $(window).height(); //画面の高さを取得
    var childs = $(this).children(); //子要素を取得

    if (scroll >= elemPos - windowHeight && !$(parent).hasClass("play")) {
      //『指定領域内にスクロールが入ったら』また『親要素にクラスplayがなければ』
      $(childs).each(function () {
        if (!$(this).hasClass("fadeUp")) {
          //アニメーションのクラス名が指定されているかどうかをチェック

          $(parent).addClass("play"); //親要素にクラス名playを追加
          $(this).css("animation-delay", value + "s"); //アニメーション遅延のCSS animation-delayを追加し
          $(this).addClass("fadeUp"); //アニメーションのクラス名を追加
          value = value + time; //delay時間を増加させる

          //全ての処理を終わったらplayを外す
          var index = $(childs).index(this);
          if (childs.length - 1 == index) {
            $(parent).removeClass("play");
          }
        }
      });
    } else {
      $(childs).removeClass("fadeUp"); //アニメーションのクラス名を削除
      value = time; //delay初期値の数値に戻す
    }
  });
}

// 画面をスクロールをしたら動かしたい場合の記述
$(window).scroll(function () {
  delayScrollAnime(); /* アニメーション用の関数を呼ぶ*/
}); // ここまで画面をスクロールをしたら動かしたい場合の記述

// 画面が読み込まれたらすぐに動かしたい場合の記述
$(window).on("load", function () {
  delayScrollAnime(); /* アニメーション用の関数を呼ぶ*/
}); // ここまで画面が読み込まれたらすぐに動かしたい場合の記述
//# sourceURL=pen.js</script>
</body>
</html>
/* 
   外部依存 CSS:
     - https://cdnjs.cloudflare.com/animate.min.css
     - https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css
   外部依存 JS (このデモは下記の JS にも依存します):
     - https://code.jquery.com/jquery-3.4.1.min.js
 */

@charset "utf-8";

/*========= レイアウトのためのCSS ===============*/

body {
  vertical-align: middle;
  text-align: center;
  width: 100%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
  background-image: linear-gradient(
    100.6deg,
    rgba(218, 185, 252, 1) 22%,
    rgba(125, 89, 252, 1) 80%
  );
}

.flex {
  display: flex;
  flex-wrap: wrap;
  margin-top: 30px;
}

.box {
  width: 200px;
  padding: 20px;
  margin: 20px 20px;
  color: #333;
  box-sizing: border-box;
  white-space: nowrap;

  background-color: rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(6.5px);
  -webkit-backdrop-filter: blur(6.5px);

  box-shadow: 0px 6px 15px 0px rgba(142, 142, 142, 0.19);
  -webkit-box-shadow: 0px 6px 15px 0px rgba(142, 142, 142, 0.19);

  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 12px;
  -webkit-border-radius: 12px;
}

li {
  list-style: none;
}

/*==================================================
スタート時は要素自体を透過0にするためのopacity:0;を指定する
===================================*/

.box {
  opacity: 0;
}

/*==================================================
ふわっ
===================================*/

.fadeUp {
  animation-name: fadeUpAnime;
  animation-duration: 0.5s;
  animation-fill-mode: forwards;
  opacity: 0;
}

@keyframes fadeUpAnime {
  from {
    opacity: 0;
    transform: translateY(100px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}
/* 
   外部依存 JS:
     - https://code.jquery.com/jquery-3.4.1.min.js
   外部依存 CSS (このデモは下記の CSS にも依存します):
     - https://cdnjs.cloudflare.com/animate.min.css
     - https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css
 */

function delayScrollAnime() {
  var time = 0.2; //遅延時間を増やす秒数の値
  var value = time;
  $(".delayScroll").each(function () {
    var parent = this; //親要素を取得
    var elemPos = $(this).offset().top; //要素の位置まで来たら
    var scroll = $(window).scrollTop(); //スクロール値を取得
    var windowHeight = $(window).height(); //画面の高さを取得
    var childs = $(this).children(); //子要素を取得

    if (scroll >= elemPos - windowHeight && !$(parent).hasClass("play")) {
      //『指定領域内にスクロールが入ったら』また『親要素にクラスplayがなければ』
      $(childs).each(function () {
        if (!$(this).hasClass("fadeUp")) {
          //アニメーションのクラス名が指定されているかどうかをチェック

          $(parent).addClass("play"); //親要素にクラス名playを追加
          $(this).css("animation-delay", value + "s"); //アニメーション遅延のCSS animation-delayを追加し
          $(this).addClass("fadeUp"); //アニメーションのクラス名を追加
          value = value + time; //delay時間を増加させる

          //全ての処理を終わったらplayを外す
          var index = $(childs).index(this);
          if (childs.length - 1 == index) {
            $(parent).removeClass("play");
          }
        }
      });
    } else {
      $(childs).removeClass("fadeUp"); //アニメーションのクラス名を削除
      value = time; //delay初期値の数値に戻す
    }
  });
}

// 画面をスクロールをしたら動かしたい場合の記述
$(window).scroll(function () {
  delayScrollAnime(); /* アニメーション用の関数を呼ぶ*/
}); // ここまで画面をスクロールをしたら動かしたい場合の記述

// 画面が読み込まれたらすぐに動かしたい場合の記述
$(window).on("load", function () {
  delayScrollAnime(); /* アニメーション用の関数を呼ぶ*/
}); // ここまで画面が読み込まれたらすぐに動かしたい場合の記述
//# sourceURL=pen.js