Responsive Bootstrap Carousel Items

坚强是说给别人听的谎言 提交于 2020-01-03 05:08:07

问题


I'm using Bootstrap carousel, I want to make my carousel responsive so that it displays a different number of items on screen depending on the screen width.

For example, lets say I have six things I want to display in a carousel.

If the person is viewing on a mobile I want to display 1 item at a time with 6 indicator buttons beneath the carousel to toggle between the rest.

<section>
    <div class="container">
        <h2>Mobile - 1 box on screen</h2>
            <div class="row">
                <div id="document-slider-mobile" class="carousel slide" data-ride="">
                    <div class="carousel-inner">
                        <ol class="carousel-indicators">
                            <li class="indicator active" data-slide-to="0" data-target="#document-slider-mobile"></li>
                            <li class="indicator" data-slide-to="1" data-target="#document-slider-mobile"></li>
                            <li class="indicator" data-slide-to="2" data-target="#document-slider-mobile"></li>
                            <li class="indicator" data-slide-to="3" data-target="#document-slider-mobile"></li>
                            <li class="indicator" data-slide-to="4" data-target="#document-slider-mobile"></li>
                            <li class="indicator" data-slide-to="5" data-target="#document-slider-mobile"></li>
                        </ol>                       
                        <div class="item col-sm-12 active"><div class="box"><h3>This is box 1</h3></div></div>
                        <div class="item col-sm-12"><div class="box"><h3>This is box 2</h3></div></div>
                        <div class="item col-sm-12"><div class="box"><h3>This is box 3</h3></div></div>
                        <div class="item col-sm-12"><div class="box"><h3>This is box 4</h3></div></div>
                        <div class="item col-sm-12"><div class="box"><h3>This is box 5</h3></div></div>
                        <div class="item col-sm-12"><div class="box"><h3>This is box 6</h3></div></div>
                    </div>
                </div>
            </div>
    </div>
</section>

However, If the person is viewing on a desktop i want to display 4 things at a time with 2 indicator buttons beneath the carousel (1st has 4 items and 2nd has 2 items).

I've created an example to demonstrate the various scenarios and what the carousel should look and behave like. The demo uses 3 different carousels to achieve this, obviously i'm looking for 1 responsive version.

Here's the jsfiddle example (you may need to resize the panel): jsfiddle

来源:https://stackoverflow.com/questions/36594717/responsive-bootstrap-carousel-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!