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

              
                
<head>
    <!-- Splide用のCSS読み込み(CDN) -->
    <link href="https://cdn.jsdelivr.net/npm/@splidejs/splide@4.1.4/dist/css/splide.min.css" rel="stylesheet">
    <!-- 自分で用意したCSSファイル -->
    <link href="style.css" rel="stylesheet">
</head>

<body>
    <main>
        <div class="splide-wrapper">
            <div id="main-carousel" class="splide main-carousel" aria-label="サムネイルスライダー。各サムネイルをクリックすると、メインのスライダーが切り替わります">
                <div class="splide__track">
                    <ul class="splide__list">
                        <li class="splide__slide"><img src="https://kekenta-it-blog.com/wp-content/uploads/2023/11/kekenta-icon.jpg" alt=""></li>
                        <li class="splide__slide"><img src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/困った顔.jpg" alt=""></li>
                        <li class="splide__slide"><img src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/困り笑い.jpg" alt=""></li>
                        <li class="splide__slide"><img src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/真顔.jpg" alt=""></li>
    
                    </ul>
                </div>
            </div>
            <div id="thumbnail-carousel" class="splide" aria-label="サムネイルスライダー。各サムネイルをクリックすると、メインのスライダーが切り替わります">
                <div class="splide__track">
                    <ul class="splide__list">
                        <li class="splide__slide"><img src="https://kekenta-it-blog.com/wp-content/uploads/2023/11/kekenta-icon.jpg" alt=""></li>
                        <li class="splide__slide"><img src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/困った顔.jpg" alt=""></li>
                        <li class="splide__slide"><img src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/困り笑い.jpg" alt=""></li>
                        <li class="splide__slide"><img src="https://kekenta-it-blog.com/wp-content/uploads/2023/07/真顔.jpg" alt=""></li>
                    </ul>
                </div>
            </div>
        </div>
    </main>
    <!-- Splide用のjsファイル読み込み(CDN) -->
    <script src="https://cdn.jsdelivr.net/npm/@splidejs/splide@4.1.4/dist/js/splide.min.js"></script>
    <!--  自分で用意したjsファイル  -->
    <script src="js/slide.js"></script>
</body>

              
            
!

CSS

              
                /* スライダー全体を囲うラッパー要素 */
.splide-wrapper {
  width: 100%;
  max-width: 250px;
  margin: 0 auto;
}

.main-carousel {
    /* メイン画像と画像リストの間の余白 */
    margin-bottom: 30px;
}

.main-carousel .splide__track {
    /* メイン画像の比率 */
    aspect-ratio: 1 / 1;
}

#thumbnail-carousel .splide__slide {
    /* 画像リストの画像の比率 */
    aspect-ratio: 1 / 1;
}

.splide__slide {
    /* 非表示中の画像は薄くする */
    opacity: 0.6;
}

.splide__slide.is-active {
    opacity: 1;
}

/* 画像が指定のサイズ内に収まるようにするためのCSS */
.splide__slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.splide__track--nav>.splide__list>.splide__slide.is-active {
  /* 表示中の画像のボーダーを除きたいときは下記を有効化する */
  /* border: none !important; */
}
              
            
!

JS

              
                document.addEventListener('DOMContentLoaded', function () {
    // メイン画像のオプション   
    var main = new Splide('#main-carousel', {
        type: 'fade', // スライドアニメをフェード形式にする
        rewind: true, // スライドをループするかどうか
        pagination: false, // ドットインジケーターを非表示
        arrows: false, // 矢印を非表示
    });

    // 画像リストのオプション
    var thumbnails = new Splide('#thumbnail-carousel', {
        rewind: true, // スライドをループするかどうか
        arrows: true, // 矢印を表示
        pagination: false, // ドットインジケーターを非表示
        isNavigation: true, // 画像クリックでスライドを切り替えられるようにする
       perPage: 3,  // 画像リストに表示する枚数
        gap: "3%" // 画像リストの余白
    });

    // メイン画像と画像リストを連動させる記述   
    main.sync(thumbnails);
    main.mount();
    thumbnails.mount();
});
              
            
!
999px

Console