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

              
                <header class="header">
  <nav class="header-nav">
    <ul class="header-list">
      <li class="header-item"><a href="#anchor01">HOME</a></li>
      <li class="header-item"><a href="#anchor02">ABOUT</a></li>
      <li class="header-item"><a href="#anchor03">SHOP</a></li>
      <li class="header-item"><a href="#anchor04">NEWS</a></li>
    </ul>
  </nav>
</header>
<!-- メインコンテンツ -->
<main>
  <section class="section01" id="anchor01">
    <h2 class="section-title">HOME</h2>
  </section>
  <section class="section02" id="anchor02">
    <h2 class="section-title">ABOUT</h2>
  </section>
  <section class="section03" id="anchor03">
    <h2 class="section-title">SHOP</h2>
    <div class="video-wrapper js-video">
      <video muted playsinline controls>
        <source
          src="https://junpei-sugiyama.com/wp-content/uploads/2022/03/sample.mp4"
          type="video/mp4"
        />
      </video>
    </div>
  </section>
  <section class="section04" id="anchor04">
    <h2 class="section-title">NEWS</h2>
  </section>
</main>

              
            
!

CSS

              
                /* 動画のスタイル */
.video-wrapper {
  text-align: center;
}
.video-wrapper video {
  width: 50%;
}

/* スムーズスクロールとヘッダーのスタイル */
html {
  scroll-behavior: smooth; /* スムーズスクロールを有効化 */
  scroll-padding-top: 70px; /* ヘッダーの高さ */
}

/* ヘッダー部分のスタイル */
.header {
  background-color: #ff9393; /* 背景色 */
  color: #fff; /* テキスト色 */
  position: fixed; /* 固定 */
  top: 0; /* 上からの位置 */
  transition: top .5s; /* アニメーション効果を追加 */
  width: 100%; /* 幅を100%に */
}

/* ヘッダーリストのスタイル */
.header-list {
  align-items: center; /* 垂直方向中央揃え */
  display: flex; /* 横並びに配置 */
  height: 70px; /* ヘッダーの高さ */
  justify-content: center; /* 左右中央寄せ */
}

/* ヘッダーアイテムのスタイル */
.header-item a {
  color: #fff; /* テキスト色 */
  padding: 10px; /* 内側の余白 */
  text-decoration: none; /* デフォルトの下線を消す */
}

/* セクションのスタイル */
section {
  background-color: rgba(255, 255, 255, .1);
  background-image: repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(255, 1, 1, .1) 10px, rgba(255, 1, 1, .1) 20px );
  background-size: auto auto;
  min-height: 300px;
  padding-bottom: 50px;
}

/* セクションタイトルのスタイル */
.section-title {
  color: #333;
  font-size: 50px;
  text-align: center;
}

/* 各セクションの背景色 */
.section01 {
  background-color: #e2ffc6;
  padding-top: 70px;
}
.section02 {
  background-color: #c6ffff;
}
.section03 {
  background-color: #ffc6ff;
}
.section04 {
  background-color: #ffe2c6;
}

              
            
!

JS

              
                // ページの読み込みが完了したときに実行する関数を設定
window.addEventListener(
  "load",
  function () {
    // 動画を再生する関数を定義
    function playVideos(videoWrappers) {
      // 動画が再生される位置を計算する
      const startPosition = window.pageYOffset + window.innerHeight;
      // 全ての動画ラッパーに対して処理を繰り返す
      for (let i = 0; i < videoWrappers.length; i++) {
        // 動画の位置を取得
        const videoPosition =
          videoWrappers[i].getBoundingClientRect().top + window.pageYOffset;
        // 動画が再生される位置までスクロールした場合、動画を再生する
        if (startPosition > videoPosition) {
          const video = videoWrappers[i].getElementsByTagName("video");
          video[0].play();
        }
      }
    }
    // クラス名が"js-video"である要素を取得
    const videoWrappers = document.getElementsByClassName("js-video");
    // クラス名が"js-video"である要素が存在する場合
    if (videoWrappers.length) {
      // 動画を再生する関数を実行
      playVideos(videoWrappers);
      // スクロール時に動画を再生する関数を実行するリスナーを設定
      window.addEventListener(
        "scroll",
        function () {
          playVideos(videoWrappers);
        },
        false
      );
    }
  },
  false
);

              
            
!
999px

Console