【问题标题】:Bootstrap carousel and responsiveness引导轮播和响应能力
【发布时间】:2017-05-01 10:47:19
【问题描述】:

我有一个显示一些用户图片的网站。图片具有正方形和固定尺寸(100x100 像素)。如果没有足够的空间在一行中显示所有用户的图片,我想创建一个轮播。如果我调整浏览器窗口的大小,我希望激活/停用此轮播。

不知道是不是很容易,bootstrap的carousel是不是最好的选择!

提前感谢您的任何建议!

【问题讨论】:

  • 我只有一个基本的引导轮播,但我认为这不是一个好的工具。 html 控制显示多少图片(使用item 类)这一事实并没有让我觉得没有很多hackery 是可能的!而且我在谷歌上找不到很多想法..!

标签: javascript twitter-bootstrap carousel


【解决方案1】:

这是你想要达到的目标吗?

https://codepen.io/glebkema/pen/QvvowE

var isCarouselPaused = false;

$( window ).on( 'load resize', function() {
  if ( document.documentElement.clientWidth >= 768 ) {
    if ( !isCarouselPaused ) {
      $( '#myCarousel' ).carousel('pause');
      isCarouselPaused = true;
    }
  } else {
    if ( isCarouselPaused ) {
      $( '#myCarousel' ).carousel('cycle');
      isCarouselPaused = false;
    }
  };
});
@import url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css');

@media (min-width: 768px) {
  .carousel .item {
    display: block;
    float: left;
    margin: 12px;
  }
  .carousel-control, 
  .carousel-indicators {
    display: none;
  }
}

/* Make the images wide and responsive. */
.carousel-inner img {
  height: auto;
  width: 100%;
}

/* Decorations */  
.carousel {
  margin-bottom: 20px;
  margin-top: 20px;
}
<div class="container">

  <div id="myCarousel" class="carousel slide" data-ride="carousel">
    <div class="carousel-inner" role="listbox">
      <div class="item active"><img src="https://placehold.it/100x100/fc3/fff/?text=1" alt=""></div>
      <div class="item"><img src="https://placehold.it/100x100/693/fff/?text=2" alt=""></div>
      <div class="item"><img src="https://placehold.it/100x100/369/fff/?text=3" alt=""></div>
      <div class="item"><img src="https://placehold.it/100x100/f63/fff/?text=4" alt=""></div>
      <div class="item"><img src="https://placehold.it/100x100/936/fff/?text=5" alt=""></div>
    </div>
    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev"><span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span><span class="sr-only">Previous</span></a>
    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span><span class="sr-only">Next</span></a>
  </div>

</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

【讨论】:

  • 有点,但不仅适用于移动分辨率。我今天早上找到了htmlstream.com/preview/unify-v1.9.8/shortcode_carousels.html,看起来就像我想要的一样!如果它可以使用引导程序,我仍然会搜索一点,以避免另一个依赖,但如果不是,我将使用 owl !谢谢你的帮助!
  • 我认为对于您的任务,使用 Oul 比重新训练 Bootstrap 更方便。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-03-10
  • 1970-01-01
  • 1970-01-01
  • 2021-10-10
  • 1970-01-01
相关资源
最近更新 更多