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

              
                #wrapper
  ul.tab#tab(role="tablist")
    li.tab-item(data-index="0",role="tab") タブ1
    li.tab-item(data-index="1",role="tab") タブ2
    li.tab-item(data-index="2",role="tab") タブ3
    li.tab-item(data-index="3",role="tab") タブ4
  .swiper-container
    .swiper-wrapper
      .swiper-slide(role="tabpanel")
        .slide-inner
          p タブ1
          p Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
      .swiper-slide(role="tabpanel")
        .slide-inner
          p タブ2
          p Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. 
      .swiper-slide(role="tabpanel")
        .slide-inner
          p タブ3
          p Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. 
      .swiper-slide(role="tabpanel")
        .slide-inner
          p タブ4
          p Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
              
            
!

CSS

              
                #wrapper{
  max-width: 500px;
  margin: 20px auto;
}
.tab{
  position: relative;
  z-index: 2;
  display: flex;
  justify-content:space-between;
  &-item{
    flex: 0 0 120px;
    border-top:1px solid #000;
    border-right:1px solid #000;
    border-left:1px solid #000;
    color:#fff;
    text-align: center;
    padding: 10px 0;
    background-color: #000;
    color:#fff;
    cursor:pointer;
    &.current{ 
      background-color: #fff;
      color:#000;   
    }
  }
}
.swiper-container{
  border:1px solid #000;
  z-index: 1;
  margin-top: -1px;
}
.slide-inner{
  padding: 20px; 
  p{
    font-size: 16px;
    line-height: 2;
  }
}
              
            
!

JS

              
                /*
+-----------------+
| VARIABLE        |
+-----------------+
*/
const tablistId = "tab";             //タブリストのID
const tabClass = "tab-item";         //タブのCLASS
const tabCurrentClass = "current";   //タブのカレントCLASS
const tabUrlparam = "tab";           //タブのURLパラメータ

/*
+-----------------+
| FUNCTION        |
+-----------------+
*/
const tablistEle = document.getElementById(tablistId);
const tabbtnEles = document.getElementsByClassName(tabClass);

const tabSwiper = new Swiper('.swiper-container',{
  autoHeight:true,
  allowTouchMove:false,
  effect:"fade",
  fadeEffect: {
    crossFade: true
  }
});

//「tabItemclass」要素をクリックしたときに実行
for( let i = 0 ; i < tabbtnEles.length ; i++ ){
  tabbtnEles[i].addEventListener("click",()=>{
    const num = tabbtnEles[i].dataset.index;
    const currentItem = tablistEle.getElementsByClassName(tabCurrentClass)[0];
    currentItem.classList.remove(tabCurrentClass);
    tabSwiper.slideTo(num);
    tabbtnEles[i].classList.add(tabCurrentClass);
    console.log(i);
  });
}

// URLパラメータ取得の関数 getParam
const getParam = (name, url) =>{
  if (!url) url = window.location.href;
  name = name.replace(/[\[\]]/g, "\\$&");
  const regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
  results = regex.exec(url);
  if (!results) return null;
  if (!results[2]) return '';
  return decodeURIComponent(results[2].replace(/\+/g, " "));
}

// Load時に最初に表示するタブの関数 initTab
const initTab = () =>{
  const number = Number(getParam(tabUrlparam));
  if( number != null && !(isNaN(number)) && 0 <= number && number < tabbtnEles.length){
    tabSwiper.slideTo(number,0);
    tabbtnEles[number].classList.add(tabCurrentClass);
  }else{
    tabbtnEles[0].classList.add(tabCurrentClass);
  }
}

initTab();
              
            
!
999px

Console