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>
  <h2>スクロールしてね</h2>
</div>
<div class="fade scrollAnim scrollFade">
  <h2>フェード(Fade)</h2>
</div>
<div class="slide scrollAnim scrollSlide">
  <h2>スライド(Slide)</h2>
</div>
<div class="scale scrollAnim scrollScale">
  <h2>スケール(Scale)</h2>
</div>
<div class="rotate scrollAnim scrollRotate">
  <h2>回転(Rotate)</h2>
</div>
<div class="flip scrollAnim scrollFlip">
  <h2>フリップ(Flip)</h2>
</div>

<div class="counter">
  <h2>座標</h2>
  <p id="no">0</p>
</div>
              
            
!

CSS

              
                /* 全体 */
.scrollAnim.ready {
  opacity: 0;
  transition: all .8s ease-in;
}
.scrollAnim.ready.active {
  opacity: 1;
}

/* スライド(Slide) */
.scrollSlide.ready {
  transform: translateX(80px);
}
.scrollSlide.ready.active {
  transform: translateX(0);
}

/* スケール(Scale) */
.scrollScale.ready {
  transform: scale(0.8);
}
.scrollScale.ready.active {
  transform: scale(1);
}

/* 回転(Rotate) */
.scrollRotate.ready {
  transform: rotate(0deg);
}
.scrollRotate.ready.active {
  transform: rotate(360deg);
}

/* フリップ(Flip) */
.scrollFlip.ready {
  transform: rotateX(-180deg);
}
.scrollFlip.ready.active {
  transform: rotateX(0deg);
}


/* ///スタイル調整/// */
div {
  width: 300px;
  height: 300px;
  margin: 40px;
  display: grid;
  place-items: center;
}
h2 {
  font: 18px sans-serif;
}
.fade {
  background-color: #F0BAD1;
}
.slide {
  background-color: #FFBBC5;
}
.scale {
  background-color: #FFC1AE;
}
.rotate {
  background-color: #FFCD93;
}
.flip {
  background-color: #FFE17B;
}

/* 座標カウンター */
.counter {
  width: auto;
  height: auto;
  padding: 10px;
  background-color: #DFDFDF;
  text-align: center;
  position: fixed;
  top: 0;
  right: 0;
}
.counter h2 {
   font-size: 14px;
}
.counter p {
  font-size: 20px;
  font-weight: bold;
}
              
            
!

JS

              
                $(function () {
  // スクロール時の処理
  $(window).scroll(function () {
    // 対象要素に初期状態のスタイルを付与
    $(".scrollAnim").addClass("ready");
  
    // ウィンドウの高さを取得
    const windowHeight = $(this).height();

    // 現在の座標を取得
    const scrollAmount = $(this).scrollTop();

    $(".ready").each(function () {
      // 対象要素の座標を取得
      const targetPosition = $(this).offset().top;

      // 対象要素が画面内に入った時の処理
      if (scrollAmount > targetPosition - windowHeight + 60) {
        $(this).addClass("active");
      } else {
        $(this).removeClass("active");
      }
      
      // 座標カウンター
      $("#no").html(scrollAmount);
    });
  });
});
              
            
!
999px

Console