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="slideshow-container">
  <div class="slideshow">
    <div class="slide active">
      <img src="https://picsum.photos/1000/450/?random=1" alt="Slide 1">
      <div class="slide-content">
        <h2>スライド1</h2>
        <p>サブテキストサブテキストサブテキスト</p>
      </div>
    </div>
    <div class="slide">
      <img src="https://picsum.photos/1000/450/?random=2" alt="Slide 2">
      <div class="slide-content">
        <h2>スライド2</h2>
        <p>サブテキストサブテキストサブテキスト</p>
      </div>
    </div>
    <div class="slide">
      <img src="https://picsum.photos/1000/450/?random=3" alt="Slide 3">
      <div class="slide-content">
        <h2>スライド3</h2>
        <p>サブテキストサブテキストサブテキスト</p>
      </div>
    </div>
  </div>
  
  <!-- ナビゲーションボタン -->
  <button class="slide-nav prev">&#10094;</button>
  <button class="slide-nav next">&#10095;</button>
  
  <!-- インジケーター -->
  <div class="slide-dots"></div>
</div>
              
            
!

CSS

              
                .slideshow-container {
    width: 100%;
    height: 90vh;
    position: relative;
    overflow: hidden;
}

.slideshow {
    width: 100%;
    height: 100%;
    position: relative;
}

.slide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
    display: none;
}

.slide.active {
    opacity: 1;
    display: block;
}

.slide img {
    width: 100%;
}

.slide-content {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 40px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    color: white;
    text-align: center;
}

/* ナビゲーションボタンのスタイル */
.slide-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    color: white;
    padding: 16px;
    border: none;
    cursor: pointer;
    font-size: 18px;
    transition: background 0.3s;
    z-index: 1;
}

.slide-nav:hover {
    background: rgba(0, 0, 0, 0.8);
}

.prev {
    left: 10px;
}

.next {
    right: 10px;
}

/* インジケーターのスタイル */
.slide-dots {
    position: absolute;
    bottom: 20px;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 10px;
    z-index: 1;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: background 0.3s;
}

.dot.active {
    background: white;
}
              
            
!

JS

              
                document.addEventListener('DOMContentLoaded', function() {
    const slides = document.querySelectorAll('.slide');
    const prevButton = document.querySelector('.prev');
    const nextButton = document.querySelector('.next');
    const dotsContainer = document.querySelector('.slide-dots');
    let currentSlide = 0;
    let slideInterval;

    // インジケーターの生成
    function createDots() {
        slides.forEach((_, index) => {
            const dot = document.createElement('div');
            dot.classList.add('dot');
            if (index === 0) dot.classList.add('active');
            dot.addEventListener('click', () => goToSlide(index));
            dotsContainer.appendChild(dot);
        });
    }

    // スライドの表示
    function showSlide(index) {
        slides.forEach(slide => {
            slide.classList.remove('active');
        });
        
        const dots = document.querySelectorAll('.dot');
        dots.forEach(dot => dot.classList.remove('active'));
        
        slides[index].classList.add('active');
        dots[index].classList.add('active');
    }

    // 次のスライドへ
    function nextSlide() {
        currentSlide = (currentSlide + 1) % slides.length;
        showSlide(currentSlide);
    }

    // 前のスライドへ
    function prevSlide() {
        currentSlide = (currentSlide - 1 + slides.length) % slides.length;
        showSlide(currentSlide);
    }

    // 特定のスライドへ移動
    function goToSlide(index) {
        currentSlide = index;
        showSlide(currentSlide);
        resetInterval();
    }

    // 自動再生の間隔をリセット
    function resetInterval() {
        clearInterval(slideInterval);
        startAutoPlay();
    }

    // 自動再生の開始
    function startAutoPlay() {
        slideInterval = setInterval(nextSlide, 5000); // 5秒ごとに次のスライドへ
    }

    // イベントリスナーの設定
    prevButton.addEventListener('click', () => {
        prevSlide();
        resetInterval();
    });

    nextButton.addEventListener('click', () => {
        nextSlide();
        resetInterval();
    });

    // キーボードナビゲーション
    document.addEventListener('keydown', (e) => {
        if (e.key === 'ArrowLeft') {
            prevSlide();
            resetInterval();
        } else if (e.key === 'ArrowRight') {
            nextSlide();
            resetInterval();
        }
    });

    // スワイプ対応(タッチデバイス用)
    let touchStartX = 0;
    let touchEndX = 0;

    document.querySelector('.slideshow').addEventListener('touchstart', (e) => {
        touchStartX = e.touches[0].clientX;
    });

    document.querySelector('.slideshow').addEventListener('touchend', (e) => {
        touchEndX = e.changedTouches[0].clientX;
        handleSwipe();
    });

    function handleSwipe() {
        const swipeThreshold = 50;
        const difference = touchStartX - touchEndX;

        if (Math.abs(difference) > swipeThreshold) {
            if (difference > 0) {
                nextSlide();
            } else {
                prevSlide();
            }
            resetInterval();
        }
    }

    // 初期化
    createDots();
    startAutoPlay();
});
              
            
!
999px

Console