ドットインストール - 3分動画でマスターできるプログラミング学習サービス

  • レッスン一覧
  • 料金プラン
    • レッスン一覧
    • 料金プラン
  • ログイン
  • 運営からのお知らせ

    • 2025/09/04 NEW

      【週刊ドットインストール】 Seoul Startup Hubがおすすめ、レッスン制作・256timesの進捗

    すべて見る
  • トップ /
  • マイページ /
  • main.js

main.js

'use strict';
{
  function check(thumnail){
    if(thumnail === thumnails[0]){
        thumnails[0].classList.add('active');
        thumnails[1].classList.remove('active');
        thumnails[2].classList.remove('active');
      }
      if(thumnail === thumnails[1]){
        thumnails[1].classList.add('active');
        thumnails[0].classList.remove('active');
        thumnails[2].classList.remove('active');
      }
      if(thumnail === thumnails[2]){
        thumnails[2].classList.add('active');
        thumnails[0].classList.remove('active');
        thumnails[1].classList.remove('active');
      }
  }

  const thumnails = document.querySelectorAll('.thumnail');
  let mainImage = document.getElementById('main-image');
  const prev = document.getElementById('prev');
  const next = document.getElementById('next');
  let activeIndex = 0;

  thumnails.forEach(thumnail => {
    thumnail.addEventListener('click', ()=> {
      mainImage.src = thumnail.src;
      check(thumnail);
      })
    });

  next.addEventListener('click', ()=> {
    activeIndex++;
    if(activeIndex > 2){
      activeIndex = 0;
    }
    mainImage.src = thumnails[activeIndex].src;
    thumnails.forEach(thumnail => {
      thumnail.classList.remove('active');
    });
    thumnails[activeIndex].classList.add('active');
  });
  
  prev.addEventListener('click', ()=> {
    activeIndex--;
    if(activeIndex < 0){
      activeIndex = 2;
    }
    mainImage.src = thumnails[activeIndex].src;
    thumnails.forEach(thumnail => {
      thumnail.classList.remove('active');
    });
    thumnails[activeIndex].classList.add('active');
  });
}
dotinstall

3分動画でマスターできるプログラミング学習サービスです。あなたもプログラミングを始めてみませんか?

サービスメニュー

  • レッスン一覧
  • 料金プラン
  • 法人向けライセンス
  • 256times
  • 運営からのお知らせ
  • プログラミング学習ガイド
  • プログラミング学習相談室
  • ヘルプ

ご利用にあたって

  • 利用規約
  • プライバシーポリシー
  • 利用者情報の外部送信について
  • 運営企業情報
  • 採用情報
  • 教材利用について
  • お問い合わせ

ソーシャルメディア

  • note
  • X (@dotinstall)
  • Facebookページ

更新情報

  • 新着レッスンRSS
  • 新着補足情報RSS

Copyright © 2011-2025 dotinstall.com. All Rights Reserved.