如何在bootstrap中修复转盘盒?

时间:2014-05-14 01:36:52

标签: javascript jquery html twitter-bootstrap carousel

有人知道如何在引导程序中修复轮播盒容器,即使图片尺寸不同吗?因为在我当前的代码中它会滑动但是盒子会根据图片大小不断变化。

代码:

<h1>Carousel</h1>
<div class="container">
    <div class="row">
        <div class="well col-md-6">
            <div id="myCarousel" class="carousel slide" data-ride="carousel">
            <ol class="carousel-indicators">
                    <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                    <li data-target="#myCarousel" data-slide-to="1"></li>
                    <li data-target="#myCarousel" data-slide-to="2"></li>
            </ol>
                <div class="carousel-inner">
                    <div class="item active"><img src="images/1.jpg" /><div class="carousel-caption">image 1</div></div>
                    <div class="item"><img src="images/2.jpg" /><div class="carousel-caption">image 2</div></div>
                    <div class="item"><img src="images/3.jpg" /><div class="carousel-caption">image 3</div></div>
                </div>
                <a class="carousel-control left" href="#myCarousel" data-slide="prev"> 
                    <span class="glyphicon glyphicon-chevron-left"></span>
                </a>
                <a class="carousel-control right" href="#myCarousel" data-slide="next">
                    <span class="glyphicon glyphicon-chevron-right"></span>
                </a>
            </div>
        </div>
    </div>
</div>

脚本:

<script type="text/javascript">
    $(document).ready(function(){
        $('.carousel').carousel({
        interval: 2000
        })
    });
</script>

2 个答案:

答案 0 :(得分:2)

这样就可以了解

   #myCarousel {
      width: 400px; // define suitable width here

    }

    .item img {
           max-width: 100%;
        }

max-width会阻止图片溢出旋转木马

答案 1 :(得分:2)

<h1>Carousel</h1> <div class="container">
    <div class="row">
        <div class="well col-md-6">
            <div id="myCarousel" class="carousel slide" data-ride="carousel">
            <ol class="carousel-indicators">
                    <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
                    <li data-target="#myCarousel" data-slide-to="1"></li>
                    <li data-target="#myCarousel" data-slide-to="2"></li>
            </ol>
                <div class="carousel-inner">
                    <div class="item fiximage active"><img src="images/1.jpg" /><div class="carousel-caption">image 1</div></div>
                    <div class="item fiximage"><img src="images/2.jpg" /><div class="carousel-caption">image 2</div></div>
                    <div class="item fiximage"><img src="images/3.jpg" /><div class="carousel-caption">image 3</div></div>
                </div>
                <a class="carousel-control left" href="#myCarousel" data-slide="prev"> 
                    <span class="glyphicon glyphicon-chevron-left"></span>
                </a>
                <a class="carousel-control right" href="#myCarousel" data-slide="next">
                    <span class="glyphicon glyphicon-chevron-right"></span>
                </a>
            </div>
        </div>
    </div> </div>

CSS

.fiximage img {
   width: auto;
   min-height: 500px;
   height: 500px;
}