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

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="item-list">
  <li class="list">
    <div class="modal-trigger">
        <div class="img">
            <img loading="lazy" class="item-img" src="https://web-kin.com/wp-content/themes/WebKin/img/mv-01.jpg" alt="">
        </div>
    </div>
  </li>
  <!-- /.list -->
  <li class="list">
    <div class="modal-trigger">
        <div class="img">
            <img loading="lazy" class="item-img" src="https://web-kin.com/wp-content/themes/WebKin/img/mv-02.jpg" alt="">
        </div>
    </div>
  </li>
  <!-- /.list -->
  <li class="list">
    <div class="modal-trigger">
        <div class="img">
            <img loading="lazy" class="item-img" src="https://web-kin.com/wp-content/themes/WebKin/img/mv-01.jpg" alt="">
        </div>
    </div>
  </li>
  <!-- /.list -->
</ul>



<!-- モーダル -->
<div class="modal-wrap">
    <div class="overlay"></div>
    <div class="modal-inner">
        <div class="img img-area">
            <img loading="lazy" class="base-img" src="">
        </div>
        <div class="modal-close"><i>×</i></div>
    </div>
    <!-- /.modal-inner -->
</div>
<!-- /.modal-wrap -->
              
            
!

CSS

              
                /*--------------------------------------------
reset
---------------------------------------------*/
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

li{
  list-style: none;
}

.item-list{
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  
  .list{
    .modal-trigger{
      img{
        max-width: 100%;
        height: auto;
      }
    }
  }
}

.modal-wrap{
  position: fixed;
  left: 0;
  display: block;
  width: 100%;
  height: 100vh;
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s linear 0s, visibility .3s linear 0s;
  
  &.show{
    top: 0;
    opacity: 1;
    visibility: visible;
    z-index: 10000;
  }
  
  .overlay{
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, .92);
    cursor: pointer;
    z-index: 10000;
  }
  
  .modal-inner{
    position: absolute;
    top: 50%;
    left: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    background-color: transparent;
    opacity: 0;
    visibility: hidden;
    z-index: 10001;
    transition: opacity .3s linear .5s, visibility .3s linear .5s;
    transform: translate(-50%, -50%);
    
    &.show{
      opacity: 1;
      visibility: visible;
    }
    
    .modal-close{
      position: absolute;
      color: #fff;
      font-size: 24px;
      cursor: pointer;
    }
  }
}

@media screen and (max-width: 767px) {
  .item-list{
    justify-content: space-between;
    padding: 0 2.6%;
    margin-top: 5px;
    
    .list{
      width: 48%;
      margin-top: 15px;
      
      .modal-trigger{
        padding: 5.8%;
        
        .img{
          width: 100%;
          height: 88px;
        }
      }
    }
  }
  
  .modal-wrap{
    .modal-inner{
      width: 90%;

      .img-area{
        height: 200px;
      }

      .note{
        font-size: 10px;
      }

      .modal-close{
        top: -32px;
        right: 0;

        .icon{
          width: 24px;
        }
      }
    }
  }
}

@media screen and (min-width: 768px) {
  .item-list{
    display: flex;
    justify-content: space-between;
    
    .list{
      width: 30%;
      
      .modal-trigger{
        .img{
          width: 100%;
          height: 200px;
          overflow: hidden;
        }
        
        &:hover{
          opacity: 0.7;
        }
      }
    }
  }
  
  .modal-wrap{
    .modal-inner{
      max-width: 950px;

      .img-area{
        height: 77vh;

        .base-img{
          max-width: initial;
          height: 100%;
        }
      }

      .modal-close{
        top: -50px;
        right: 0;

        img {
          max-width: 85%;
        }
      }
    }
  }
}
              
            
!

JS

              
                //モーダル
//-------------------------------------------------------------
function modalFunc () {
  //変数の設定
  var $modalTrigger = $('.modal-trigger'),
      $modalWrap = $('.modal-wrap'),
      $overlay = $('.overlay'),
      $modalInner = $('.modal-inner'),
      $modalClose = $('.modal-close');
  
  //サムネイルをクリックしたときの挙動
  $modalTrigger.on('click', function(){
    $modalWrap.addClass('show');
    $modalInner.addClass('show');
  });
  
  //モーダルの×ボタンをクリックしたときの挙動
  $modalClose.on('click', function(){
    hideModal();
  });
  
  //オーバーレイ領域をクリックしたときの挙動
  $overlay.on('click', function(){
    hideModal();
  });
  
  //モーダルを消すための処理
  var hideModal = function () {
    $modalWrap.removeClass('show');
    $modalInner.removeClass('show');
  }
}




// モーダル内の画像をスイッチ
//-------------------------------------------------------------
function switchImageFunc() {
  var $modalTrigger =$('.modal-trigger'),
      $modalWrap =$('.modal-wrap'),
      $target = $modalWrap.find('.img-area').find('img');
  
  //トリガーをクリック
  $modalTrigger.on('click', function(e) {
    e.preventDefault();
    
    //トリガーに使用している画像のsrc属性の値を取得
    $src = $(this).find('img').attr('src');
    
    //モーダル内のimgタグに取得した値を設定
    $target.attr('src', $src);
    
   $('.img-area').zoom();
  })
}




// ベース画像のsrcをカラにする
//-------------------------------------------------------------
function deleteBaseImageSrc() {
  var $overlay = $('.overlay'),
      $modalClose = $('.modal-close');
  
  //モーダルの×ボタンをクリックしたときの挙動
  $modalClose.on('click', function(){
    deleteSrc();
  });
  
  //オーバーレイ領域をクリックしたときの挙動
  $overlay.on('click', function(){
    deleteSrc();
  });
  
  //ベースの画像読み込みパスをリセット
  function deleteSrc() {
    $('.base-img').attr('src', '');
  }
}




// ズーム用の画像を削除
//-------------------------------------------------------------
function removeOldImage() {
  var $overlay = $('.overlay'),
      $modalClose = $('.modal-close');
  
  //モーダルの×ボタンをクリックしたときの挙動
  $modalClose.on('click', function(){
    removeImg();
  });
  
  //オーバーレイ領域をクリックしたときの挙動
  $overlay.on('click', function(){
    removeImg();
  });
  
  //ズーム用の画像を削除
  function removeImg() {
    var $zoomImg = $('.modal-wrap').find('.img-area').find('.zoomImg');
    $zoomImg.remove();
  }
}


modalFunc();
switchImageFunc();
deleteBaseImageSrc();
removeOldImage();
              
            
!
999px

Console