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

              
                <p class="desc">Please Slide Right</p>
<section class="cat">
  <ul class="items">
    <li class="item __1 is-show"></li>
    <li class="item __2 is-show"></li>
    <li class="item __3 is-show"></li>
    <li class="item __4"></li>
    <li class="item __5"></li>
    <li class="item __1"></li>
    <li class="item __2"></li>
    <li class="item __3"></li>
    <li class="item __4"></li>
    <li class="item __5"></li>
  </ul>
</section>
              
            
!

CSS

              
                body {
  background-color: #4d4557;
}
.desc {
  color: #fff;
  font-size: 24px;
  padding: 1em;
}
.items {
  background-color: #f5c043;
  width: 50vw;
  margin: 40px auto 40px 0;
  display: flex;
  overflow-x: scroll;
  overflow-y: hidden;
  overflow-scrolling: touch; /* スクロールを滑らかにする */
  -webkit-overflow-scrolling: touch; /* スクロールを滑らかにする */
}
.item {
  flex: 0 0 calc(100% / 3 - 5%);
  margin-right: 5%;
  height: 0;
  padding-top: 40%;
  background-size: cover;
  background-position: top;
  opacity: 0;
  transform: translateY(100%);
  transition: all 1s cubic-bezier(0, 0.55, 0.45, 1);
  &.is-show {
    opacity: 1;
    transform: translateY(0);
  }
}

.item {
  &.__1 {
    background-image: url(https://images.unsplash.com/photo-1514888286974-6c03e2ca1dba?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1927&q=80);
  }
  &.__2 {
    background-image: url(https://images.unsplash.com/photo-1511044568932-338cba0ad803?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80);
  }
  &.__3 {
    background-image: url(https://images.unsplash.com/photo-1478098711619-5ab0b478d6e6?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80);
  }
  &.__4 {
    background-image: url(https://images.unsplash.com/photo-1533743983669-94fa5c4338ec?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=683&q=80);
  }
  &.__5 {
    background-image: url(https://images.unsplash.com/photo-1494256997604-768d1f608cac?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=801&q=80);
  }
}

              
            
!

JS

              
                "use strict";

{
  // ターゲット(複数)
  const targets = document.querySelectorAll(".item");

  // ターゲットが交差した時の処理
  function doWhenTargetObserve(entries, observerStop) {
    //複数ターゲットを1つずつ取り出す
    entries.forEach((entry) => {
      // 監視範囲にないときは何もしない
      if (!entry.isIntersecting) {
        return;
      }
      // 監視範囲と交差したときの処理
      entry.target.classList.add("is-show");
      //一度処理したら監視をやめる
      observerStop.unobserve(entry.target);
    });
  }
  // 監視範囲
  const rootTarget = document.querySelector(".items");
  const options = {
    // root: null,//画面全体がroot
    root: rootTarget, //スライダー内がroot
    rootMargin: "0% -50% 0% 0%", //範囲の右から50%で交差
    threshold: 0
  };
  const observer = new IntersectionObserver(doWhenTargetObserve, options);

  // ターゲットを監視
  targets.forEach((target) => {
    observer.observe(target);
  });
}

              
            
!
999px

Console