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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

            
              #wrapper
  dl
    dt(data-acc="acc1").js-accbtn アコーディオンボタン1
    dd(data-acc="acc1").js-acccontent
      .inner
        p アコーディオンボタン内容1
    dd(data-acc="acc2").js-acccontent
      .inner
        p アコーディオンボタン2はこっちも開くよ
  dl
    dt(data-acc="acc2").js-accbtn アコーディオンボタン2
    dd(data-acc="acc2").js-acccontent
      .inner
        p アコーディオンボタン内容2
        p アコーディオンボタン内容2
        p アコーディオンボタン内容2
        p アコーディオンボタン内容2
            
          
!

CSS

            
              .js-acccontent{
  display: none;
}
#wrapper{
  max-width:500px;
  width: 100%;
  margin: 20px auto;
}
dl{
  border-bottom: 1px solid #fff;
}
dt{
  background-color: #1a1a1a;
  padding: 15px 20px 15px 15px;
  color:#fff;
  position: relative;
  &:after{
    content:'';
    display: block;
    width: 0;
    height: 0;
    transition:.3s all ease;
    border-top: 8px solid #fff;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 0 solid transparent;
    position: absolute;
    right: 10px;
    top: 50%;
    margin-top: -4px;
  }
  &.open{
    &:after{
      border-bottom: 8px solid #fff;
      border-top: 0 solid transparent;
      
    }
  }
}
dd{
  .inner{
    padding: 15px;
    background-color: #ddd;  
    line-height: 1.7;  
  }
}
            
          
!

JS

            
              // define variable -------------------------
const accbtns = document.getElementsByClassName('js-accbtn');
const acccontents = document.getElementsByClassName('js-acccontent');
const accOpenClass = "open";
const accSpeed = 300;
const accDivisor = 30;
const accInterval = accSpeed/accDivisor;

// define function -------------------------
const accClick= ()=>{
  for(let i = 0; i < accbtns.length ; i++){
    accbtns[i].addEventListener('click',(e)=>{
      const accid  = accbtns[i].getAttribute('data-acc');
      if( e.currentTarget.classList.contains(accOpenClass) ){
        accClose(accid,i);
      }else{
        accOpen(accid,i);
      }
    });
  }
}

const accOpen = (id,i) =>{
  accbtns[i].classList.add(accOpenClass);
  for(let n = 0; n < acccontents.length; n++){
    const accid = acccontents[n].getAttribute('data-acc');
    if( id == accid ){
      const accOpenFirst = (callback)=>{
        acccontents[n].style.display = "block";
        const height = acccontents[n].clientHeight;
        acccontents[n].style.display = "none";
        callback(height);
      }
      accOpenFirst((height) =>{
        const nowH = 0;
        const initCount = 0;
        const minH = height/accDivisor;
        acccontents[n].style.display = "block";
        acccontents[n].style.height = '0px';
        acccontents[n].style.overflow = "hidden";
        accOpenInterval(nowH,minH,n,initCount);
      });
    }
  }
}

const accOpenInterval =(nowH,minH,n,count)=>{
  const nextH = nowH + minH;
  count ++;
  acccontents[n].style.height = `${nextH}px`;
  if( count < accDivisor){
    setTimeout(accOpenInterval,accInterval,nextH,minH,n,count);
  }else{
    acccontents[n].style.overflow = "";
  }
}

const accClose = (id,i) =>{
  accbtns[i].classList.remove(accOpenClass);
  for(let n = 0; n < acccontents.length; n++){
    const accid = acccontents[n].getAttribute('data-acc');
    if( id == accid ){
      const accCloseFirst = (callback)=>{
        const height = acccontents[n].clientHeight;
        acccontents[n].style.overflow = "hidden";
        callback(height);
      }
      accCloseFirst((height)=>{
        const nowH = height;
        const initCount = 0;
        const minH = height/accDivisor;
        accCloseInterval(nowH,minH,n,initCount);
      });
    }
  }
}

const accCloseInterval =(nowH,minH,n,count)=>{
  const nextH = nowH - minH;
  count++;
  acccontents[n].style.height = `${nextH}px`;
  if( count < accDivisor){
    setTimeout(accCloseInterval,accInterval,nextH,minH,n,count);
  }else{
    acccontents[n].style.display = "none";
    acccontents[n].style.height = "";
    acccontents[n].style.overflow = "";
  }
}

// exe function -------------------------
accClick();
            
          
!
999px

Console