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

              
                #wrapper
  header.head
    .logo takblog
  #memubtn.memubtn
  nav.nav#nav
    .nav-inner
      ul.glnav
        li.glnav-item
          a(href="#") HOME
        li.glnav-item
          a(href="#") ABOUT
        li.glnav-item
          a(href="#") PRODUCTS
        li.glnav-item
          a(href="#") NEWS
        li.glnav-item
          a(href="#") IR
        li.glnav-item
          a(href="#") CONTACT
  main.main
    .kv
      img(src="https://takblog.site/wp-content/uploads/2019/08/javascript3-1.jpg", alt="")
    p ダミーテキストダミーテキストダミーテキストダミーテキストダミーテキストダミーテキストダミーテキストダミーテキストダミーテキストダミーテキストダミーテキストダミーテキスト

              
            
!

CSS

              
                // ---------------------------
// 大事な変数定義
// ---------------------------
$openClass:navOpen;
$nav_z-index:100;
$ease-time:.3s;

// ---------------------------
// 大事なstyle
// ---------------------------
#wrapper{
  // メニューオープン時の各style
  &.#{$openClass}{
    // メニューオープン時にコンテンツエリアがスクロールしないように position: fixed;
    position: fixed;
    left: 0;
    width: 100%;
    height: 100%;
    .nav{
      transform:translateY(0);
    }
    .memubtn{
      &:before{
        content:'close';
        color:#fff;
      }
    }
  }
}
.nav{
  position:fixed;
  z-index: $nav_z-index;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  // スマホでのスクロールを滑らかにするためのstyle
  -webkit-overflow-scrolling: touch;
  overflow-scrolling: touch;
  overflow-y: auto;  
  transform: translateY(-100%); // ここはお好みで
  transition: $ease-time transform ease; // ここはお好みで  
  &-inner{
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
    overflow-y:auto;
  }
}

// 今回はgooleのMaterial iconsを使用してmenubtnを作成
.memubtn{
  display: block;
  position:fixed;
  right: 15px;
  top: 10px;
  z-index: #{$nav_z-index+1};  //navのz-indexより大きく
  color:#000;
  &:before{
    content:'menu';
    font-family: 'Material Icons';
    font-size: 40px;
  }
}

// ---------------------------
// デザイン調整のためのstyle
// ---------------------------
img{
  width: 100%;
}
.head{
  height: 80px;
  .logo{
    text-align: center;
    height: 80px;
    line-height: 80px;
    font-size: 30px;
  }
}
.main{
  display: block;
  max-width:1230px;
  padding-left: 15px;
  padding-right: 15px;
  margin: 0 auto;
}

.nav{
  background-color: rgba(0,0,0,.8);
  &-inner{
    padding:40px 15px;
  }
}
.glnav{
  &-item{
    text-align: center;
    padding: 20px 0;
    a{
      color:#fff;
      font-size: 20px;      
    }
  }
}
              
            
!

JS

              
                // 変数定義 -------------------------
const memubtn = document.getElementById('memubtn');  // メニュー開閉のボタン
const wrapper = document.getElementById('wrapper'); // ページ全体を囲む要素 wrapper
const nav = document.getElementById('nav');         // ドロワーメニュー要素 nav
const openClass = 'navOpen';                        // メニューオープン時に wrapper につくclass
let navopen = false;                                // メニューオープンの判定

// 関数定義 -------------------------
const navToggle = () =>{
  if( navopen ){
    navClose();
  }else{
    navOpen();
  }
}

// メニューオープン時の関数
const navOpen = () =>{
  navopen = true;
  const top = window.pageYOffset;
  wrapper.setAttribute('style',`top:-${top}px`);
  wrapper.classList.add(openClass);
}

// メニュークローズ時の関数
const navClose = () =>{
  const closeFirst = (callback)=>{
    navopen = false;
    let scrolltop = wrapper.style.top;
    scrolltop = scrolltop.slice(1,-2);
    wrapper.style.top = "";
    wrapper.classList.remove(openClass);
    callback(scrolltop);
  }
  closeFirst((scrolltop)=>{
    window.scrollTo(0, scrolltop);
  });
}


// 関数実行 -------------------------
if( memubtn != null){
  memubtn.addEventListener('click', navToggle, false);
}

              
            
!
999px

Console