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

              
                <p>↓スクロールすると表示される要素が動きます。</p>
<div class="boxes-wrapper">
  <div class="scroll-in box box-01"></div>
  <div class="scroll-in box box-02"></div>
</div>
              
            
!

CSS

              
                p{
  text-align: center
}
.boxes-wrapper{
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-top: 300px;
  margin-bottom: 100px;
}
.box{
  width: 30px;
  height: 30px;
  background-color: #333;
}
.box-01.displayed{
  animation: rotate-01 2s forwards;
}
.box-02.displayed{
  animation: rotate-02 2s forwards;
}
@keyframes rotate-01{
  0%{transform: rotate(300deg);}
100%{transform: rotate(0);}
}
@keyframes rotate-02{
  0%{transform: rotate(0);}
100%{transform: rotate(300deg);}
}
              
            
!

JS

              
                //クラス名が「scroll-in」の要素を取得
const objects = document.querySelectorAll('.scroll-in');

//スクロール感知で実行
const cb = function(entries, observer) {
    entries.forEach(entry => {
        if(entry.isIntersecting) {
            entry.target.classList.add('displayed');//スクロール感知で「displayed」のクラス名を付与
            observer.unobserve(entry.target); //監視の終了
        }
    });
}
// オプション
const options = {
    root: null,
    rootMargin: "0px",
    threshold: 0
}

// IntersectionObserverインスタンス化
const io = new IntersectionObserver(cb, options);

// 監視を開始
objects.forEach(object => {
    io.observe(object);
});
              
            
!
999px

Console