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

              
                
<div class="javaSample">
   <!-- コンテンツ -->
    <div class="swiperModalButton">
      <button class="modalOpen" data-modal="1">スライダー1</button>
      <button class="modalOpen" data-modal="2">スライダー2</button>
      <button class="modalOpen" data-modal="3">スライダー3</button>
      <button class="modalOpen" data-modal="4">スライダー4</button>
      <button class="modalOpen" data-modal="5">スライダー5</button>
      <button class="modalOpen" data-modal="6">スライダー6</button>
    </div>

    <!-- モーダル -->
    <div class="modal" id="modal">
      <div class="modal__overlay modalClose"></div>
      <div class="modal__content">
        <div class="modal_inner">
        <div class="modal__close-btn modalClose" aria-label="閉じる"><span class="lineClose"></span></div>
        <!-- スライダー -->
        <div class="swiper modalInSlider">
          <div class="swiper-wrapper">
            <div class="swiper-slide modalInSlider"><p class="swiperText">スライド1</p></div>
            <div class="swiper-slide modalInSlider"><p class="swiperText">スライド2</p></div>
            <div class="swiper-slide modalInSlider"><p class="swiperText">スライド3</p></div>
            <div class="swiper-slide modalInSlider"><p class="swiperText">スライド4</p></div>
            <div class="swiper-slide modalInSlider"><p class="swiperText">スライド5</p></div>
            <div class="swiper-slide modalInSlider"><p class="swiperText">スライド6</p></div>
          </div>
        </div>
        </div>
          <div class="swiper-button-prev"></div>
          <div class="swiper-button-next"></div>
      </div>
    </div>
<!-- ここまで -->
</div>
              
            
!

CSS

              
                
/* ---------------------------- */
/* --- Base --- */
/* ---------------------------- */
.swiperModalButton {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: space-around;
}

/* モーダル */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  padding: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s;
  pointer-events: none;
  opacity: 0;
  z-index: 100;
  background-color: rgba(255, 255, 255, 0.9);
}

/* モーダルがactiveの時 */
.modal.is-active {
  opacity: 1;
  pointer-events: auto;
}

/* モーダル背景のオーバーレイ部分 */
.modal__overlay {
  position: absolute;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* モーダルのコンテンツ */
.modal__content {
    position: relative;
    width: 100%;
    max-width: 800px;
    padding: 20px;
}
.modal_inner {
    filter: drop-shadow(0px 0px 4px #ddd);
    background: #FFF;
    width: 90%;
    margin: 0 auto;
    border-radius: 2px;
    padding: 20px 25px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
}

/* 閉じるボタン */
.modal__close-btn {
    position: absolute;
    right: 0;
    top: -40px;
    width: 40px;
    height: 40px;
    cursor: pointer;
    z-index: 20;
}
.modal__close-btn:hover {
    opacity: 0.8;
}

/* 閉じるボタンのX */
.lineClose {
    display: inline-block;
    vertical-align: middle;
    color: #313131;
    line-height: 1;
    width: 2rem;
    height: 0.1rem;
    background: currentColor;
    border-radius: 0.1rem;
    position: relative;
    transform: rotate(45deg);
}
.lineClose::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: inherit;
  border-radius: inherit;
  transform: rotate(90deg);
}
p.swiperText {
    margin: 0;
    text-align: center;
}
              
            
!

JS

              
                
window.addEventListener("DOMContentLoaded", () => {
  // モーダルを取得
  const modal = document.getElementById("modal");
  // モーダルを開く
  const openModalBtns = document.querySelectorAll(".modalOpen");
  // モーダルを閉じる
  const closeModalBtns = document.querySelectorAll(".modalClose");

  // Swiperの設定
  const swiper = new Swiper(".swiper", {
    loop: true,
    navigation: {
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev",
    },
    spaceBetween: 30, //任意のマージン
  });

  // モーダルのボタンクリック
  openModalBtns.forEach((openModalBtn) => {
    openModalBtn.addEventListener("click", () => {
      // data-modalで設定したスライド番号を取得
      const modalIndex = openModalBtn.getAttribute('data-modal');
      swiper.slideTo(modalIndex);
      modal.classList.add("is-active");
    });
  });

  // モーダルの閉じるボタンクリック
  closeModalBtns.forEach((closeModalBtn) => {
    closeModalBtn.addEventListener("click", () => {
      modal.classList.remove("is-active");
    });
  });
});
              
            
!
999px

Console