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
  .modal(data-modal="modal1",aria-hidden="true",tabindex="-1",aria-labelledby="modal1-title",aria-describedby="modal1-description")
    .modal__content
      h2#modal1-title モーダルウィンドウ1
      p#modal1-description モーダルウィンドウ1の説明
      p あのイーハトーヴォのすきとおった風、夏でも底に冷たさをもつ青いそら、うつくしい森で飾られたモリーオ市、郊外のぎらぎらひかる草の波。 またそのなかでいっしょになったたくさんのひとたち、ファゼーロとロザーロ、羊飼のミーロや、顔の赤いこどもたち、地主のテーモ、山猫博士のボーガント・デストゥパーゴなど、いまこの暗い巨きな石の建物のなかで考えていると、みんなむかし風のなつかしい青い幻燈のように思われます。では、わたくしはいつかの小さなみだしをつけながら、しずかにあの年のイーハトーヴォの五月から十月までを書きつけましょう。
      button.modal__open(data-modal="modal2") モーダル2オープン
      button.modal__close モーダルクローズ
  .modal(data-modal="modal2",aria-hidden="true",tabindex="-1",aria-labelledby="modal2-title",aria-describedby="modal2-description")
    .modal__content
      h2#modal2-title モーダルウィンドウ2
      p#modal2-description モーダルウィンドウ2の説明
      button.modal__open(data-modal="modal1") モーダル1オープン
      button.modal__close モーダルクローズ

  button.modal__open(data-modal="modal1") モーダル1オープン
  button.modal__open(data-modal="modal2") モーダル2オープン
              
            
!

CSS

              
                *{
  box-sizing: border-box;
}
.wrapper{
  height: 1000px;
  &.is-modalopen{
    position: fixed;
    left: 0;
    width: 100%;
    overflow: hidden;
  }
}
.modal{ 
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 99;
  opacity: 0;
  visibility: hidden;
  transition: .3s opacity ease , 0s visibility .3s linear;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
  &.is-open{
  transition: .3s opacity ease , 0s visibility 0s linear;
    opacity: 1;
    visibility: visible;   
  }
  &__content{
    position: relative;
    z-index: 2;
    padding: 20px;
    background-color: #fff;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    flex:0 1 1000px;
    width: 100%;
    max-width: 1000px;
    max-height: 100%;
  }
  &__bg{
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.8);
  }
  &__open,&__close{
    display: block;
    width: 300px;
    height: 50px;
    margin: 20px auto;    
  }
}

              
            
!

JS

              
                (function(){
    const openbtns = document.querySelectorAll('.modal__open');
    const closebtns = document.querySelectorAll('.modal__close');
    const wrapper = document.querySelector('.wrapper');
    
    const modalOpen = (btn)=>{
      modalClose();
      const modalId = btn.dataset.modal;
      const modal = document.querySelector(`.modal[data-modal="${modalId}"]`);
      modal.insertAdjacentHTML('beforeend','<i class="modal__bg"></i>');
      modal.classList.add('is-open');
      const top = window.pageYOffset;
      wrapper.classList.add('is-modalopen');
      wrapper.style.top = `-${top}px`;
      // START アクセシビリティ考慮       
      modal.setAttribute('aria-modal','true');
      modal.setAttribute('role','dialog');
      modal.setAttribute('aria-hidden','false');
      modal.setAttribute('tabindex','0');
      modal.focus();
      // END アクセシビリティ考慮
      const modalbg = document.querySelector('.modal__bg');
      modalbg.addEventListener('click',()=>{
        modalClose();
      });
    }
  
    const modalClose = ()=>{
      const modal = document.querySelector(`.modal.is-open`);
      if( modal == null){ return false; }
      // START アクセシビリティ考慮 
      modal.removeAttribute('aria-modal');
      modal.removeAttribute('role');
      modal.setAttribute('aria-hidden','true');
      modal.setAttribute('tabindex','-1');
      // END アクセシビリティ考慮
      const getY =(callback)=> {
        modal.classList.remove('is-open');
        const modalbg = document.querySelector('.modal__bg');
        const top = wrapper.style.top;
        const y = top.slice(1,-2);
        wrapper.style.top = '';
        wrapper.classList.remove('is-modalopen');
        modalbg.parentNode.removeChild(modalbg);
        callback(y);
      }
      getY((y)=>{
        window.scrollTo(0,y);
      });      
    }
    
    openbtns.forEach(openbtn=>{
      openbtn.addEventListener('click',(event)=>{
        const btn = event.currentTarget;
        modalOpen(btn);
      });
    });

  closebtns.forEach(closebtn=>{
      closebtn.addEventListener('click',()=>{
        modalClose();
      });
    });

})();
              
            
!
999px

Console