๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Lect & Tip/bootstrap

โœˆ Bootstrap 4 Carousel : ์ž๋™ ์žฌ์ƒ ์ค‘์ง€ ๋ฐฉ๋ฒ• ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์Šฌ๋ผ์ด๋”

by ๋‚ฏ์„ ๊ณต๊ฐ„2019 2019. 10. 27.

๋ชฉ์ฐจ

    ์ฒ˜์Œ ํผ๋ธ”๋ฆฌ์…”๋ฅผ ์‹œ์ž‘ํ–ˆ์„ ๋•Œ ๋‚ด๊ฒŒ ์นด๋ฃจ์…€(Carousel)์€ ์•…๋ชฝ๊ฐ™์€ ์กด์žฌ์˜€๋‹ค.

    ํด๋ผ์ด์–ธํŠธ๋“ค์ด ์š”๊ตฌํ•˜๋Š” ๊ฐ์ข… ์‚ฌ์•ˆ์„ ์ ์šฉํ•ด์„œ ์Šฌ๋ผ์ด๋”๋ฅผ ๋งค๋ฒˆ ์ƒˆ๋กœ ๋งŒ๋“ค์–ด์•ผ ํ–ˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

    ์š”์ฆ˜์€ ๋ถ€ํŠธ์ŠคํŠธ๋žฉ๊ฐ™์€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ๋งŽ์ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ์–ด์„œ ์Šฌ๋ผ์ด๋” ๊ตฌํ˜„์ด ๋„ˆ๋ฌด ํŽธํ•˜๋‹ค.

    Bootstrap 4๋Š” ๋ณ„๋กœ ์นœ์ ˆํ•˜์ง€ ์•Š๋‹ค.

    Bootstrap 4์— ์นด๋ฃจ์…€ ์Šฌ๋ผ์ด๋”๊ฐ€ ์žˆ์ง€๋งŒ, ์ฒ˜์Œ๋ถ€ํ„ฐ ์ž๋™์žฌ์ƒ์ด๋‹ค.

    ์ด๊ฑธ ์›ํ•œ๋‹ค๋ฉด ๋„ˆ๋ฌด๋„ ๊ฐ„ํŽธํ•œ ๋ฐฉ๋ฒ•์ด์ง€๋งŒ, ์ฒ˜์Œ์— ๋ฉˆ์ถฐ ์žˆ๊ธฐ๋ฅผ ์›ํ•œ๋‹ค๋ฉด ์ด ๋•Œ๋Š” ํŒจ๋‹‰์ด๋‹ค.

    ๋ฐฉ๋ฒ•์€ ์˜์™ธ๋กœ ๊ฐ„๋‹จํ•˜๊ณ  ๋ฌด๊ถ๋ฌด์ง„ํ•˜๋‹ค.

    ๋จผ์ € ์˜ˆ์ œ๋ฅผ ๋ณด์ž.

    <div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
      <div class="carousel-inner">
        <div class="carousel-item active">
            <img src="..." class="d-block w-100" alt="...">
        </div>
        <div class="carousel-item">
          <img src="..." class="d-block w-100" alt="...">
        </div>
        <div class="carousel-item">
          <img src="..." class="d-block w-100" alt="...">
        </div>
      </div>
    </div>

    ๊ฐ€์žฅ ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ•์€ 

    data-ride =”carousel”

    ๋ฅผ ๋นผ ๋ฒ„๋ฆฌ๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

    ์ด๊ฒŒ ์—†์œผ๋ฉด ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์Šฌ๋ผ์ด๋”๋Š” ๋ฉˆ์ถฐ ์žˆ๋‹ค.

    ์•„๋‹ˆ ๋ฉˆ์ถฐ๋‘๋ฉด ์ด๊ฒŒ ๋ญ๋ƒ? ์‹ถ๊ฒ ์ง€๋งŒ ๋ถ€ํŠธ์ŠคํŠธ๋žฉ ์Šฌ๋ผ์ด๋”๋Š” Prev, Next๋ฅผ ์ง€์›ํ•œ๋‹ค.

    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
      <div class="carousel-inner">
        <div class="carousel-item active">
          <img src="..." class="d-block w-100" alt="...">
        </div>
        <div class="carousel-item">
          <img src="..." class="d-block w-100" alt="...">
        </div>
        <div class="carousel-item">
          <img src="..." class="d-block w-100" alt="...">
        </div>
      </div>
      <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
        <span class="carousel-control-prev-icon" aria-hidden="true"></span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
        <span class="carousel-control-next-icon" aria-hidden="true"></span>
        <span class="sr-only">Next</span>
      </a>
    </div>

    ํผ๋ธ”๋ฆฌ์‹ฑ ๋‹จ๊ณ„์—์„œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋‚˜ ์ œ์ด์ฟผ๋ฆฌ๋ฅผ ๋งŒ์งˆ ํ•„์š”๋„ ์—†๋‹ค.

    ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์€ 

    data-interval = "false"

    ๋ฅผ ์ถ”๊ฐ€ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

    ์ถ”๊ฐ€ํ•˜๋Š๋‹ˆ ๋นผ๋Š”๊ฒŒ ๋‚ซ๋‹ค.

    ๊ทธ ์ด์™ธ์˜ ๋ฐฉ๋ฒ•์€ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ๊ฑด๋“œ๋ฆฌ๊ณ  ์‹ถ์„ ๋•Œ ์Šคํฌ๋ฆฝํŠธ ๋‹จ์—์„œ ์ œ์–ดํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

    <script>
        $(document).ready(function() {      
            $('.carousel').carousel('pause');
        });
    </script>

    ์ด๊ฒŒ ๋จนํž ๊ฒƒ์ด๋ผ๊ณ  ๊ธฐ๋Œ€ํ•˜์ง€ ์•Š๋Š” ์‚ฌ๋žŒ๋“ค๋„ ์žˆ์ง€๋งŒ ์ด๊ฒŒ ๋จนํžˆ๋„ค~

    ๊ทธ๋ฆฌ๊ณ  ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ data-interval = "false" ๋Œ€์‹ ์— ์Šคํฌ๋ฆฝํŠธ์— interval: false๋ฅผ ์ฃผ๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

    <script>
        $(document).ready(function() {      
            $('.carousel').carousel(
            	interval: false
            );
        });
    </script>

    ๋ฐ˜์‘ํ˜•

    ๋Œ“๊ธ€