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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <ul class="header-nav js-header-nav">
  <li><a href="#">Main</a></li>
  <li><a href="#News">News</a></li>
  <li><a href="#price">Price</a></li>
  <li><a href="#access">Access</a></li>
  <li><a href="#contact">Contact</a></li>
</ul>

<div class="box">
</div>
<div class="box2">
</div>
<div class="box3">
</div>

<script
  src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous"></script> 
              
            
!

CSS

              
                ul,
li {
  margin: 0;
  padding: 0;
  list-style: none;
}

.header-nav {
  /* liアイテムを横並び */
  display: flex;
  /* ul全体の幅・高さ */
  width: 100%;
  height: 100px;
  background: pink;
}
.header-nav li {
  /* メニュー名を左右中央寄せ */
  text-align: center;
  /* li box の高さをulに合わせる */
  line-height: 100px;
  width: calc(100% / 5);
}
.header-nav li a {
  /* リンクをブロックいっぱいに */
  display: block;
  color: #fff;
  text-decoration: none;
}
.fixed.header-nav {
  position: fixed;
  /* top: 0; ←はjQeryで指定済み*/
  background: rgba(119, 150, 56, .8);
}
.fixed.header-nav li:hover{
  background: rgba(104, 138, 35, .6);  
}
  /* スクロールダウン時に下に影をつける*/
.fixed.header-nav {
  box-shadow: 0 10px 10px rgba(0,0,0,0.1);
}
.box {
  height: 1000px;
  width: 100%;
  background: skyblue;
}
.box2 {
  height: 1000px;
  width: 100%;
  background: rgb(236, 252, 203);
}
.box3 {
  height: 1000px;
  width: 100%;
  background: rgb(164, 164, 252);
}

              
            
!

JS

              
                $(function() {
  let headNav = $(".js-header-nav");
  //scrollしたとき
  $(window).on("scroll", function() {
    //現在の位置が200px以上かつ、クラスfixedが付与されていない(false)時
    if ($(this).scrollTop() > 200 && headNav.hasClass("fixed") == false) {
      //headerの高さ分上に設定(上から降りてくるようにするため)
      headNav.css({ top: "-100px" });
      //クラスfixedを付与
      headNav.addClass("fixed");
      //位置を0に設定。1秒かけてアニメーションでにゅるっと降りてくる
      headNav.animate({ top: 0 }, 1000);
    } else if ($(this).scrollTop() <= 200 && headNav.hasClass("fixed") == true) {
      //現在の位置が200px以下かつ、クラスfixedが付与されている時にfixedを外す
      headNav.removeClass("fixed");
      
      //場合によってフロートナビゲーションの残像が残ることがあったので追記。必要ない場合は削除してください。
    } else if($(this).scrollTop() <= 200) { 
       headNav.removeClass("fixed");
    }
  });
});

              
            
!
999px

Console