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>
  </section>
  <section class="section04" id="anchor04">
    <h2 class="section-title">NEWS</h2>
  </section>
</main>

              
            
!

CSS

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

/* ヘッダー部分のスタイル */
.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;
  height: 300px;
}

/* セクションタイトルのスタイル */
.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

              
                $(document).ready(function () {
  // ウィンドウのスクロール量を保持する変数
  let start_position = 0,
    window_position;
  // ヘッダー要素を取得
  const header = $("header");
  // スクロールイベントを設定
  $(window).scroll(function () {
    // 現在のウィンドウのスクロール量を取得
    window_position = $(window).scrollTop();
    // ヘッダーの高さを取得
    const headerHeight = header.outerHeight();
    // スクロール量が初期位置より小さい場合、上にスクロールしているのでヘッダーを表示
    if (window_position <= start_position) {
      header.css("top", "0");
    } else {
      // スクロール量が初期位置より大きい場合、下にスクロールしているのでヘッダーを非表示
      header.css("top", -headerHeight + "px");
    }
    // 現在の位置を更新
    start_position = window_position;
  });
  // ページ読み込み時に中途半端な位置でロードされたときでも正しくヘッダーの表示を設定するためにスクロールイベントを発生させる
  $(window).trigger("scroll");
});

              
            
!
999px

Console