Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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

              
                <div class="box-wrapper">
  <p class="text">スクロール↓</p>
    <div class="box js-scroll-fall">
      <div class="item"></div>
    </div>
  </div>
              
            
!

CSS

              
                .box-wrapper {
  position: relative;
  max-width: 600px;
  height: 100vh;
  margin: 0 auto;
  text-align: center;
}

.text {
  padding: 20px;
}

.box {
  width: 100%;
}

/* 落ち葉 */
.item {
  position: absolute;
  left: 50%;
  transform: translate(-50%, 0);
  width: 15px;
  height: 20px;
  margin: 0 auto;
  border-radius: 0% 70%;
  background: #914928;
  opacity: 0;
}

@keyframes fall {
  from {
    opacity: 0;
    top: -50px;
  }

  20% {
    opacity: 1;
  }

  to {
    opacity: 1;
    top: 100vh;
  }
}

@keyframes sway1 {
  from {
    transform: translate3d(0px, 0px, 0px) rotate(0deg);
  }

  25% {
    transform: translate3d(-50px, 0px, 0px) rotate(-10deg);
  }

  75% {
    transform: translate3d(50px, 0px, 0px) rotate(10deg);
  }

  to {
    transform: translate3d(0px, 0px, 0px) rotate(0deg);
  }
}

.js-scroll-fall.is-animated .item {
  animation: fall 4s linear forwards, sway1 4s ease-in-out alternate;
  animation-delay: 0.3s;/* アニメーション遅延で個々のアニメーション開始をずらしたい場合、数値を変えてつける */
}
              
            
!

JS

              
                let targets = document.querySelectorAll('.js-scroll-fall'); //ターゲット要素
//スクロールイベント
window.addEventListener('scroll', function () {
  var scroll = window.scrollY; //スクロール量を取得
  var windowHeight = window.innerHeight; //画面の高さを取得
  for (let target of targets) { //ターゲット要素がある分、アニメーション用のクラスをつける処理を繰り返す
    var targetPos = target.getBoundingClientRect().top + scroll; //ターゲット要素の位置を取得
    if (scroll > targetPos - windowHeight) { //スクロール量 > ターゲット要素の位置
      target.classList.add('is-animated'); //is-animatedクラスを加える
    }
  }
});
              
            
!
999px

Console