<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<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 ===============*/

/*スクロールダウン全体の場所*/
.scrolldown {
  /*描画位置※位置は適宜調整してください*/
  position: absolute;
  bottom: 10px;
  right: 50%;
  /*マウスの動き1.6秒かけて動く永遠にループ*/
  animation: mousemove 1.6s ease-in-out infinite;
}

/*下からの距離が変化して上から下に動く*/
@keyframes mousemove {
  0% {
    bottom: 10px;
  }
  50% {
    bottom: 5px;
  }
  100% {
    bottom: 10px;
  }
}

/*Scrollテキストの描写*/
.scrolldown span {
  z-index: 10;
  /*描画位置*/
  position: absolute;
  left: -15px;
  bottom: 45px;
  /*テキストの形状*/
  color: #000;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

/*マウスの中の線描写 */
.scrolldown span::after {
  z-index: 10;
  content: "";
  /*描画位置*/
  position: absolute;
  top: 10px;
  left: 17px;
  /*線の形状*/
  width: 1px;
  height: 15px;
  background: #000;
  /*線の動き1.4秒かけて動く。永遠にループ*/
  animation: mousepathmove 1.4s linear infinite;
  opacity: 0;
}

/*上からの距離・不透明度・高さが変化して上から下に流れる*/
@keyframes mousepathmove {
  0% {
    height: 0;
    top: 10px;
    opacity: 0;
  }
  50% {
    height: 15px;
    opacity: 1;
  }
  100% {
    height: 0;
    top: 30px;
    opacity: 0;
  }
}

/*マウスの描写 */
.scrolldown:before {
  z-index: 10;
  content: "";
  /*描画位置*/
  position: absolute;
  bottom: 0;
  left: -10px;
  /*マウスの形状*/
  width: 25px;
  height: 37px;
  border-radius: 10px;
  border: 1px solid #000;
}

/*マウスの中の丸の描写*/
.scrolldown:after {
  z-index: 10;
  content: "";
  /*描画位置*/
  position: absolute;
  bottom: 26px;
  left: 0;
  /*丸の形状*/
  width: 5px;
  height: 5px;
  border-radius: 50%;
  border: 1px solid #000;
}

/*========= スクロールのためのCSS ===============*/
.space {
  padding: 100vh 0;
}

/*========= レイアウトのためのCSS ===============*/
body {
  background-image: linear-gradient(
    68.4deg,
    rgba(248, 182, 204, 1) 0.5%,
    rgba(192, 198, 230, 1) 60%,
    rgba(225, 246, 240, 1) 89.8%
  );
}

p {
  text-align: center;
  padding: 20px 0;
  font-size: 1.3rem;
  letter-spacing: 0.2em;
  overflow: hidden; /*左右アニメーションで画面からはみ出る際に出る横スクロールバーを隠す*/
}

/*========= くるくる回るテキスト ===============*/

.rollAnime.roll span {
  transition-property: opacity, transform;
  transform: rotateY(360deg);
  transition: all 0.8s cubic-bezier(0.77, 0, 0.175, 1);
  transition-timing-function: cubic-bezier(0.77, 0, 0.175, 1);
  display: inline-block;
}</style>
</head>
<body>
<body>
<div class="scrolldown">
<span>Scroll</span>
</div>
<div class="wrapper">
<p class="rollAnime">WEB Navigator</p>
<p class="rollAnime">TEXT animation</p>
<div class="space">
</div>
<p class="rollAnime">WEB Navigator</p>
<p class="rollAnime">TEXT animation</p>
</div>
<script>// rollAnimeにrollというクラス名を付ける定義
function RollAnimeControl() {
  $(".rollAnime").each(function () {
    var elemPos = $(this).offset().top - 50;
    var scroll = $(window).scrollTop();
    var windowHeight = $(window).height();
    var childs = $(this).children(); //rollAnimeの子要素を取得
    if (scroll >= elemPos - windowHeight) {
      $(childs).each(function (i) {
        //子要素を1つ1つ処理をおこなう
        if (i < 10) {
          //10未満の場合
          $(this).css("transition-delay", "." + i + "s"); //子要素にcsstransition-delayを追加
        } else {
          //10以上の場合
          var n = i / 10; //ミリ秒指定なので10で割る
          $(this).css("transition-delay", n + "s"); //子要素にcsstransition-delayを追加
        }
      });

      $(this).addClass("roll"); //rollというアニメーションクラスを付与
    } else {
      $(childs).each(function () {
        //子要素を1つ1つ処理をおこなう
        $(this).css("transition-delay", "0s"); //子要素にcsstransition-delayの秒を0とする
      });
      $(this).removeClass("roll"); //rollというアニメーションクラスを除去
    }
  });
}

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

// 画面が読み込まれたらすぐに動かしたい場合の記述
$(window).on("load", function () {
  //spanタグを追加する
  var element = $(".rollAnime");
  element.each(function () {
    var text = $(this).text();
    var textbox = [];
    text.split("").forEach(function (t, i) {
      if (t !== " ") {
        if (i < 10) {
          textbox +=
          '<span style="transition-delay:.' + i + 's;">' + t + "</span>";
        } else {
          var n = i / 10;
          textbox +=
          '<span style="transition-delay:' + n + 's;">' + t + "</span>";
        }
      } else {
        textbox += t;
      }
    });
    $(this).html(textbox);
  });

  RollAnimeControl(); /* アニメーション用の関数を呼ぶ*/
}); // ここまで画面が読み込まれたらすぐに動かしたい場合の記述
//# sourceURL=pen.js</script>
</body>
</html>
/* 
   外部依存 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 ===============*/

/*スクロールダウン全体の場所*/
.scrolldown {
  /*描画位置※位置は適宜調整してください*/
  position: absolute;
  bottom: 10px;
  right: 50%;
  /*マウスの動き1.6秒かけて動く永遠にループ*/
  animation: mousemove 1.6s ease-in-out infinite;
}

/*下からの距離が変化して上から下に動く*/
@keyframes mousemove {
  0% {
    bottom: 10px;
  }
  50% {
    bottom: 5px;
  }
  100% {
    bottom: 10px;
  }
}

/*Scrollテキストの描写*/
.scrolldown span {
  z-index: 10;
  /*描画位置*/
  position: absolute;
  left: -15px;
  bottom: 45px;
  /*テキストの形状*/
  color: #000;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

/*マウスの中の線描写 */
.scrolldown span::after {
  z-index: 10;
  content: "";
  /*描画位置*/
  position: absolute;
  top: 10px;
  left: 17px;
  /*線の形状*/
  width: 1px;
  height: 15px;
  background: #000;
  /*線の動き1.4秒かけて動く。永遠にループ*/
  animation: mousepathmove 1.4s linear infinite;
  opacity: 0;
}

/*上からの距離・不透明度・高さが変化して上から下に流れる*/
@keyframes mousepathmove {
  0% {
    height: 0;
    top: 10px;
    opacity: 0;
  }
  50% {
    height: 15px;
    opacity: 1;
  }
  100% {
    height: 0;
    top: 30px;
    opacity: 0;
  }
}

/*マウスの描写 */
.scrolldown:before {
  z-index: 10;
  content: "";
  /*描画位置*/
  position: absolute;
  bottom: 0;
  left: -10px;
  /*マウスの形状*/
  width: 25px;
  height: 37px;
  border-radius: 10px;
  border: 1px solid #000;
}

/*マウスの中の丸の描写*/
.scrolldown:after {
  z-index: 10;
  content: "";
  /*描画位置*/
  position: absolute;
  bottom: 26px;
  left: 0;
  /*丸の形状*/
  width: 5px;
  height: 5px;
  border-radius: 50%;
  border: 1px solid #000;
}

/*========= スクロールのためのCSS ===============*/
.space {
  padding: 100vh 0;
}

/*========= レイアウトのためのCSS ===============*/
body {
  background-image: linear-gradient(
    68.4deg,
    rgba(248, 182, 204, 1) 0.5%,
    rgba(192, 198, 230, 1) 60%,
    rgba(225, 246, 240, 1) 89.8%
  );
}

p {
  text-align: center;
  padding: 20px 0;
  font-size: 1.3rem;
  letter-spacing: 0.2em;
  overflow: hidden; /*左右アニメーションで画面からはみ出る際に出る横スクロールバーを隠す*/
}

/*========= くるくる回るテキスト ===============*/

.rollAnime.roll span {
  transition-property: opacity, transform;
  transform: rotateY(360deg);
  transition: all 0.8s cubic-bezier(0.77, 0, 0.175, 1);
  transition-timing-function: cubic-bezier(0.77, 0, 0.175, 1);
  display: inline-block;
}
/* 
   外部依存 JS:
     - https://code.jquery.com/jquery-3.4.1.min.js
   外部依存 CSS (このデモは下記の CSS にも依存します):
     - https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css
 */

// rollAnimeにrollというクラス名を付ける定義
function RollAnimeControl() {
  $(".rollAnime").each(function () {
    var elemPos = $(this).offset().top - 50;
    var scroll = $(window).scrollTop();
    var windowHeight = $(window).height();
    var childs = $(this).children(); //rollAnimeの子要素を取得
    if (scroll >= elemPos - windowHeight) {
      $(childs).each(function (i) {
        //子要素を1つ1つ処理をおこなう
        if (i < 10) {
          //10未満の場合
          $(this).css("transition-delay", "." + i + "s"); //子要素にcsstransition-delayを追加
        } else {
          //10以上の場合
          var n = i / 10; //ミリ秒指定なので10で割る
          $(this).css("transition-delay", n + "s"); //子要素にcsstransition-delayを追加
        }
      });

      $(this).addClass("roll"); //rollというアニメーションクラスを付与
    } else {
      $(childs).each(function () {
        //子要素を1つ1つ処理をおこなう
        $(this).css("transition-delay", "0s"); //子要素にcsstransition-delayの秒を0とする
      });
      $(this).removeClass("roll"); //rollというアニメーションクラスを除去
    }
  });
}

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

// 画面が読み込まれたらすぐに動かしたい場合の記述
$(window).on("load", function () {
  //spanタグを追加する
  var element = $(".rollAnime");
  element.each(function () {
    var text = $(this).text();
    var textbox = [];
    text.split("").forEach(function (t, i) {
      if (t !== " ") {
        if (i < 10) {
          textbox +=
          '<span style="transition-delay:.' + i + 's;">' + t + "</span>";
        } else {
          var n = i / 10;
          textbox +=
          '<span style="transition-delay:' + n + 's;">' + t + "</span>";
        }
      } else {
        textbox += t;
      }
    });
    $(this).html(textbox);
  });

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