Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <p style="width: 100%; font-size: 20px; line-height: 30px; text-align: center; margin-top: 48vh;">下にスクロールしてみてください。</p>

<div class="fadeAnimation">
  <div class="fadeAnimation__item js-fadeAnimation fadeIn">
    <div class="fadeAnimation__itemInner">
      <p class="fadeAnimation__text">フェードイン</p>
    </div>
  </div><!-- /.fadeAnimation__item -->

  <div class="fadeAnimation__item js-fadeAnimation fadeUp delay04s">
    <div class="fadeAnimation__itemInner">
      <p class="fadeAnimation__text">フェードイン(下から上へ)</p>
    </div>
  </div><!-- /.fadeAnimation__item -->

  <div class="fadeAnimation__item js-fadeAnimation fadeDown delay2s">
    <div class="fadeAnimation__itemInner">
      <p class="fadeAnimation__text">フェードイン(上から下へ)</p>
    </div>
  </div><!-- /.fadeAnimation__item -->

  <div class="fadeAnimation__item js-fadeAnimation fadeRight delay04s">
    <div class="fadeAnimation__itemInner">
      <p class="fadeAnimation__text">フェードイン(左から右へ)</p>
    </div>
  </div><!-- /.fadeAnimation__item -->

  <div class="fadeAnimation__item js-fadeAnimation fadeLeft delay04s">
    <div class="fadeAnimation__itemInner">
      <p class="fadeAnimation__text">フェードイン(右から左へ)</p>
    </div>
  </div><!-- /.fadeAnimation__item -->
</div><!-- /.fadeAnimation -->
              
            
!

CSS

              
                /*------------------------------
 fadeAnimation デモ用装飾
------------------------------*/
.fadeAnimation {
  display: flex;
  flex-flow: row wrap;
  max-width: 96%;
  margin: 60vh auto;
}

.fadeAnimation__item {
  width: 32%;
  height: 40vh;
  background-color: #202f55;
  margin: 0 auto 60vh;
}

.fadeAnimation__itemInner {
  display: table;
  width: 100%;
  height: 100%;
}

.fadeAnimation__text {
  display: table-cell;
  color: #ffffff;
  font-size: 18px;
  text-align: center;
  vertical-align: middle;
  padding: 10px;
  box-sizing: border-box;
}

/*------------------------------
 アニメーション
------------------------------*/
.fadeIn {
  opacity: 0;
}

.fadeUp {
  opacity: 0;
  transform: translateY(50px);
}

.fadeDown {
  opacity: 0;
  transform: translateY(-50%);
}

.fadeRight {
  opacity: 0;
  transform: translateX(-50%);
}

.fadeLeft {
  opacity: 0;
  transform: translateX(50%);
}

.delay01s {
  animation-delay: 0.1s;
}

.delay02s {
  animation-delay: 0.2s;
}

.delay03s {
  animation-delay: 0.3s;
}

.delay04s {
  animation-delay: 0.4s;
}

.delay05s {
  animation-delay: 0.5s;
}

.delay06s {
  animation-delay: 0.6s;
}

.delay07s {
  animation-delay: 0.7s;
}

.delay08s {
  animation-delay: 0.8s;
}

.delay09s {
  animation-delay: 0.9s;
}

.delay1s {
  animation-delay: 1s;
}

.delay2s {
  animation-delay: 2s;
}

.fadeIn.is-animated {
  animation-name: fadeIn;
  animation-duration: 1s;
  animation-fill-mode: both;
}

.fadeUp.is-animated {
  animation-name: fadeUp;
  animation-duration: 1s;
  animation-fill-mode: both;
}

.fadeDown.is-animated {
  animation-name: fadeDown;
  animation-duration: 1s;
  animation-fill-mode: both;
}

.fadeRight.is-animated {
  animation-name: fadeRight;
  animation-duration: 1s;
  animation-fill-mode: both;
}

.fadeLeft.is-animated {
  animation-name: fadeLeft;
  animation-duration: 1s;
  animation-fill-mode: both;
}

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

@keyframes fadeUp {
  0% {
    opacity: 0;
    transform: translateY(50px);
  }
  100% {
    opacity: 1;
    transform: translateY(0px);
  }
}

@keyframes fadeDown {
  0% {
    opacity: 0;
    transform: translateY(-50px);
  }
  100% {
    opacity: 1;
    transform: translateY(0px);
  }
}

@keyframes fadeRight {
  0% {
    opacity: 0;
    transform: translateX(-50%);
  }
  100% {
    opacity: 1;
    transform: translateX(0px);
  }
}

@keyframes fadeLeft {
  0% {
    opacity: 0;
    transform: translateX(50%);
  }
  100% {
    opacity: 1;
    transform: translateX(0px);
  }
}

              
            
!

JS

              
                // Scroll fade-in animation
(function () { // 即時実行関数(グローバル汚染対策)
  let i = 0; // for文用変数の定義
  let el = {}; // 配列・変数用(巻き上げ防止の為、冒頭にて宣言)

  // DOM読み込み後のタイミングで処理
  document.addEventListener('DOMContentLoaded', function () {
    el.targetElement = document.querySelectorAll('.js-fadeAnimation'); // フェードアニメーション表示させる要素のセレクタ指定
    el.firstDisplayOnlyFlag = false; // フェードアニメーション表示を1回のみにするかの判定フラグ(true:1回のみ、false:複数回)
  }, false);

  // スクロール時の処理
  window.addEventListener('scroll', function () {
    scrollAnimationFnc(); // スクロールアニメーション用関数の実行
  }, false);

  // 向き切り替え(リサイズ)時の処理
  window.addEventListener('resize', function () {
    scrollAnimationFnc(); // スクロールアニメーション用関数の実行
  }, false);

  // スクロールアニメーション用関数
  function scrollAnimationFnc () {
    el.scrollValue = window.pageYOffset || document.documentElement.scrollTop; // 現在のスクロール量の取得
    el.documentHeight = document.documentElement.clientHeight; // ドキュメント全体の高さ(スクロールバー含ない)を取得(表示領域部分の高さ)

    for (i = 0; i < el.targetElement.length; ++i) {
      el.clientRect = el.targetElement[i].getBoundingClientRect(); // 対象要素のViewpor(ビューポート)に対する相対位置に関する情報を取得
      el.targetPosition = el.clientRect.top + el.scrollValue; // 対象要素の位置座標を取得
      el.targetHeight = el.targetElement[i].offsetHeight; // 対象要素のborder、paddingを含んだ高さを取得

      if (el.scrollValue < el.targetPosition - el.documentHeight || el.scrollValue > el.targetPosition + el.targetHeight) {
        // ドキュメント全体の高さ(スクロールバー含ない)内(表示領域)に対象要素の位置が入っていなければ処理
        if (!el.firstDisplayOnlyFlag) {
          // 判定フラグが「false(複数回)」の場合に処理
          el.targetElement[i].classList.remove('is-animated'); // 対象要素から「is-animated」classを削除する
        } else {
          // 判定フラグが「true(1回のみ)」の場合に処理
          return false; // 処理を中断
        }
      } else {
        // ドキュメント全体の高さ(スクロールバー含ない)内(表示領域)に対象要素の位置が入っていれば処理
        el.targetElement[i].classList.add('is-animated'); // 対象要素に「is-animated」classを付与する
      }
    }
  }
}());
              
            
!
999px

Console