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

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

CSS

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

.box {
  width: 100%;
  text-align: center;
}

.text {
  padding: 20px;
}

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

.item--horizontal {
  width: 20px;
  height: 15px;
}

.item--color2 {
  background: #ada137;
}

.item--color3 {
  background: #44681e;
}

@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);
  }
}

@keyframes sway2 {
  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);
  }
}

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

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

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

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


.js-scroll-fall.is-animated .item:nth-child(1) {
  animation: fall 4s linear forwards, sway1 4s ease-in-out alternate;
}

.js-scroll-fall.is-animated .item:nth-child(2) {
  left: 56%;
  animation: fall 4s linear forwards, sway2 4s ease-in-out alternate;
  animation-delay: 0.3s;
}

.js-scroll-fall.is-animated .item:nth-child(3) {
  left: 40%;
  transform: translate3d(0px, 0px, 0px) rotate(90deg);
  animation: fall 4s linear forwards, sway1 4s ease-in-out alternate;
  animation-delay: 0.5s;
}

.js-scroll-fall.is-animated .item:nth-child(4) {
  left: 43.5%;
  transform: translate3d(0px, 0px, 0px) rotate(120deg);
  animation: fall 4s linear forwards, sway2 4s ease-in-out alternate;
  animation-delay: 0.7s;
}

.js-scroll-fall.is-animated .item:nth-child(5) {
  left: 54%;
  transform: translate3d(0px, 0px, 0px) rotate(60deg);
  animation: fall 4s linear forwards, sway1 4s ease-in-out alternate;
  animation-delay: 0.9s;
}

.js-scroll-fall.is-animated .item:nth-child(6) {
  left: 45%;
  transform: translate3d(0px, 0px, 0px) rotate(30deg);
  animation: fall 4s linear forwards, sway2 4s ease-in-out alternate;
  animation-delay: 1s;
}

.js-scroll-fall.is-animated .item:nth-child(7) {
  left: 50%;
  transform: translate3d(0px, 0px, 0px) rotate(-65deg);
  animation: fall 4s linear forwards, sway2 4s ease-in-out alternate;
  /* animation-delay: 1s; */
}

.js-scroll-fall.is-animated .item:nth-child(8) {
  left: 55%;
  transform: translate3d(0px, 0px, 0px) rotate(40deg);
  animation: fall 4s linear forwards, sway2 4s ease-in-out alternate;
  animation-delay: 0.2s;
}

.js-scroll-fall.is-animated .item:nth-child(9) {
  left: 70%;
  transform: translate3d(0px, 0px, 0px) rotate(-30deg);
  animation: fall 4s linear forwards, sway2 4s ease-in-out alternate;
  animation-delay: 0.5s;
}

.js-scroll-fall.is-animated .item:nth-child(10) {
  left: 65%;
  transform: translate3d(0px, 0px, 0px) rotate(-135deg);
  animation: fall 4s linear forwards, sway2 4s ease-in-out alternate;
  animation-delay: 0.7s;
}

.js-scroll-fall.is-animated .item:nth-child(11) {
  left: 60%;
  transform: translate3d(0px, 0px, 0px) rotate(135deg);
  animation: fall 4s linear forwards, sway3 4s ease-in-out alternate;
  animation-delay: 0.9s;
}

.js-scroll-fall.is-animated .item:nth-child(12) {
  left: 53%;
  transform: translate3d(0px, 0px, 0px) rotate(-120deg);
  animation: fall 4s linear forwards, sway1 4s ease-in-out alternate;
  animation-delay: 0.8s;
}

.js-scroll-fall.is-animated .item:nth-child(13) {
  left: 40%;
  transform: translate3d(0px, 0px, 0px) rotate(-120deg);
  animation: fall 4s linear forwards, sway3 4s ease-in-out alternate;
  animation-delay: 0.3s;
}

.js-scroll-fall.is-animated .item:nth-child(14) {
  left: 35%;
  transform: translate3d(0px, 0px, 0px) rotate(-120deg);
  animation: fall 4s linear forwards, sway1 4s ease-in-out alternate;
  animation-delay: 0.4s;
}

.js-scroll-fall.is-animated .item:nth-child(15) {
  left: 30%;
  transform: translate3d(0px, 0px, 0px) rotate(120deg);
  animation: fall 4s linear forwards, sway3 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