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

              
                <h1>スクロールしてください</h1>
<div class="box"><img src="https://source.unsplash.com/400x400/?food,yellow" alt=""></div>
<div class="box"><img src="https://source.unsplash.com/400x400/?food,red" alt=""></div>
<div class="box"><img src="https://source.unsplash.com/400x400/?food,blue" alt=""></div>
<div class="box"><img src="https://source.unsplash.com/400x400/?food,orange" alt=""></div>
<div class="box"><img src="https://source.unsplash.com/400x400/?food,gray" alt=""></div>
<div class="box"><img src="https://source.unsplash.com/400x400/?food,pink" alt=""></div>
<div class="box"><img src="https://source.unsplash.com/400x400/?food,gold" alt=""></div>
<div class="box"><img src="https://source.unsplash.com/400x400/?food,black" alt=""></div>
<div class="box"><img src="https://source.unsplash.com/400x400/?food,white" alt=""></div>
<div class="box"><img src="https://source.unsplash.com/400x400/?food,purple" alt=""></div>
<div class="box"><img src="https://source.unsplash.com/400x400/?food,green" alt=""></div>
<div class="box"><img src="https://source.unsplash.com/400x400/?food,darkcyan" alt=""></div>
<div class="box"><img src="https://source.unsplash.com/400x400/?food,chololate" alt=""></div>
              
            
!

CSS

              
                .box {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
  transition: 0.7s ease-out;
  & img {
    box-shadow: 2px 4px 5px rgba(0, 0, 0, 0.3);
    border-radius: 1rem;
    display: block;
    opacity: 0;
    transition: 0.4s ease-out 0.5s;
  }
  &:nth-of-type(even) {
    transform: translateX(-200%);
  }
  &:nth-of-type(odd) {
    transform: translateX(200%);
  }
  &.show {
    transform: translateX(0);
    & img {
      opacity: 1;
    }
  }
}

              
            
!

JS

              
                window.addEventListener("load", () => {
  // boxをすべて取得
  const boxes = document.querySelectorAll(".box");
  // scrollイベントをセット
  window.addEventListener("scroll", showBoxes);

  showBoxes();

  function showBoxes() {
    // 発火位置
    const triggerBottom = (window.innerHeight / 5) * 4;

    boxes.forEach((box) => {
      // boxの頭部分の座標を取得
      const boxTop = box.getBoundingClientRect().top;

      // boxの頭部分が発火位置を超えたら
      if (boxTop < triggerBottom) {
        box.classList.add("show");
      } else {
        box.classList.remove("show");
      }
    });
  }
});

              
            
!
999px

Console