为什么我的旋转木马不能正常工作?

时间:2016-09-03 15:48:36

标签: html css carousel

请帮助我,当我运行代码时,我只能在页面上看到旋转木马,但我看不到任何图像,按钮也不起作用。

在代码段中查看下面的CSS + HTML。

#my-carousel .carousel-inner .item {
    width: 100%;
    height: 300px;
}
#my-carousel .carousel-inner .item {
	background-image:url(../images/windsurfing.jpg)
    background-size: cover;
    background-position: center top;
}
#my-carousel .carousel-inner .item-2 {
	background-image:url(../images/kitesurf.jpg)
}
#my-carousel .carousel-inner .item-3 {
	background-image:url(../images/sup.jpg)
}
@media (min-width:768px) { 
    #my-carousel .carousel-inner .item {
        height: 500px
    }
}
<div class="containter">

      <div class="carousel carousel-fade slide" id="my-carousel">

        <ol class="carousel-indicators">
            <li data-target="#my-carousel" data-slide-to="0"></li>
            <li data-target="#my-carousel" data-slide-to="1"></li>
            <li data-target="#my-carousel" data-slide-to="2"></li>
        </ol>

        <div class="carousel-inner">
          <div class="item active item-1">
       </div>
          <div class="item item-2" >
       </div>
          <div class="item item-3">
       </div>
        </div>
        <!--  remove the a href tag to remove link that does not need it -->

        <a href="#my-carousel" class="carousel-control left" data-slide="prev"><!-- <span class="glyphicon glyphicon-chevron-left"></span> --></a>
        <a href="#my-carousel" class="carousel-control right" data-slide="next"><!-- <span class="glyphicon glyphicon-chevron-right"></span> --></a>

    </div>

</div>

2 个答案:

答案 0 :(得分:0)

&#13;
&#13;
#my-carousel .carousel-inner .item {
    width:100%;
    height: 300px;
    background-repeat: no-repeat;
}
#my-carousel .carousel-inner .item-1 {
	background-image:url('http://54.245.110.34/pk/img/02.jpg')
    
}
#my-carousel .carousel-inner .item-2 {
	background-image:url('http://54.245.110.34/pk/img/03.jpg')
}
#my-carousel .carousel-inner .item-3 {
	background-image:url('https://placehold.it/600x300')
}
@media (min-width:768px) { 
    #my-carousel .carousel-inner .item {
        height: 500px
    }
}
&#13;
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>



<div class="containter">

      <div class="carousel carousel-fade slide" id="my-carousel" data-ride="carousel">

        <ol class="carousel-indicators">
            <li data-target="#my-carousel" data-slide-to="0"></li>
            <li data-target="#my-carousel" data-slide-to="1"></li>
            <li data-target="#my-carousel" data-slide-to="2"></li>
        </ol>

        <div class="carousel-inner">
          <div class="item  item-1 active">
       </div>
          <div class="item item-2" >
       </div>
          <div class="item item-3">
       </div>
        </div>
        <!--  remove the a href tag to remove link that does not need it -->

        <a href="#my-carousel" class="carousel-control left" data-slide="prev"><!-- <span class="glyphicon glyphicon-chevron-left"></span> --></a>
        <a href="#my-carousel" class="carousel-control right" data-slide="next"><!-- <span class="glyphicon glyphicon-chevron-right"></span> --></a>

    </div>

</div>
&#13;
&#13;
&#13;

您需要将data-ride="carousel"属性添加到您的轮播ID(#my-carousel)以使用数据属性触发它。 虽然你也可以使用像$('.carousel').carousel()

这样的js触发器触发它

这里是参考bootstrap carousel trigger

答案 1 :(得分:0)

* { box-sizing: border-box; }
body { font-family: sans-serif; }

.carousel {
  background: black;
}
.carousel-cell {
  width: 70%;
  height: 200px;
  /* flex-box, center image in cell */
  display: -webkit-box; 
  display: -webkit-flex;
  display:         flex
    -webkit-box-pack: center;
  -webkit-justify-content: center;
  justify-content: center;
  -webkit-align-items: center;
  align-items: center;
}
.carousel-cell img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  /* dim unselected */
  opacity: 0.7;
  -webkit-transform: scale(0.85);
  transform: scale(0.85);
  -webkit-filter: blur(5px);
  filter: blur(5px);
  -webkit-transition: opacity 0.3s, -webkit-transform 0.3s, transform 0.3s, -webkit-filter 0.3s, filter 0.3s; 
  transition: opacity 0.3s, transform 0.3s, filter 0.3s;
} 
/* brighten selected image */
.carousel-cell.is-selected img { 
  opacity: 1;
  -webkit-transform: scale(1);
  transform: scale(1);
  -webkit-filter: none;
  filter: none;
}
@media screen and ( min-width: 768px ) {
  .carousel-cell {
    height: 400px;
  } 
}
@media screen and ( min-width: 960px ) { 
  .carousel-cell {
    width: 60%;
  }
}
/* buttons, no circle */
.flickity-prev-next-button {
  width: 60px;
  height: 60px;
  background: transparent;
  opacity: 0.6;
} 
.flickity-prev-next-button:hover {
  background: transparent;
  opacity: 1;
}
/* arrow color */
.flickity-prev-next-button .arrow {
  fill: white;
}
.flickity-prev-next-button.no-svg {
  color: white;
}
/* closer to edge */
.flickity-prev-next-button.previous { left: 0; }
.flickity-prev-next-button.next { right: 0; }
/* hide disabled button */
.flickity-prev-next-button:disabled {
  display: none;
}
<!-- Flickity HTML init --> 
<div class="carousel js-flickity"> 
  <!-- images from unsplash.com -->
  <div class="carousel-cell">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/orange-tree.jpg" alt="orange tree" />
  </div> 

  <div class="carousel-cell">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/submerged.jpg" alt="submerged" />
  </div>

  <div class="carousel-cell">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/look-out.jpg" alt="look-out" />
  </div>

  <div class="carousel-cell">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/one-world-trade.jpg" alt="One World Trade" />
  </div>

  <div class="carousel-cell">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/drizzle.jpg" alt="drizzle" />
  </div>

  <div class="carousel-cell">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/cat-nose.jpg" alt="cat nose" />
  </div>

  <div class="carousel-cell">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/contrail.jpg" alt="contrail" />
  </div>

  <div class="carousel-cell">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/golden-hour.jpg" alt="golden hour" />
  </div> 

  <div class="carousel-cell">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/flight-formation.jpg" alt="flight formation" />
  </div>
</div> 

请检查此链接:https://css-tricks.com/creating-responsive-touch-friendly-carousels-with-flickity/