javascript - Bootstrap Carousel 未显示在页面上

标签 javascript jquery twitter-bootstrap

我正在尝试添加 Bootstrap 轮播,当我检查元素时,dom 可用但没有显示。

我正在使用从这个链接下载的自定义 Bootstrap 库:

BootStrap Custom Link

我的模板中缺少什么。

这是我尝试过的:

html:

<div id="myCarousel" class="carousel slide" data-ride="carousel">
      <!-- Indicators -->
      <ol class="carousel-indicators">
        <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
        <li data-target="#myCarousel" data-slide-to="1" class=""></li>
        <li data-target="#myCarousel" data-slide-to="2" class=""></li>
      </ol>
      <div class="carousel-inner" role="listbox">
        <div class="item active">
          <img class="first-slide" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="First slide">
          <div class="container">
            <div class="carousel-caption">
              <h1>Example headline.</h1>
              <p>Note: If you're viewing this page via a <code>file://</code> URL, the "next" and "previous" Glyphicon buttons on the left and right might not load/display properly due to web browser security rules.</p>
              <p><a class="btn btn-lg btn-primary" href="#" role="button">Sign up today</a></p>
            </div>
          </div>
        </div>
        <div class="item">
          <img class="second-slide" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Second slide">
          <div class="container">
            <div class="carousel-caption">
              <h1>Another example headline.</h1>
              <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
              <p><a class="btn btn-lg btn-primary" href="#" role="button">Learn more</a></p>
            </div>
          </div>
        </div>
        <div class="item">
          <img class="third-slide" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Third slide">
          <div class="container">
            <div class="carousel-caption">
              <h1>One more for good measure.</h1>
              <p>Cras justo odio, dapibus ac facilisis in, egestas eget quam. Donec id elit non mi porta gravida at eget metus. Nullam id dolor id nibh ultricies vehicula ut id elit.</p>
              <p><a class="btn btn-lg btn-primary" href="#" role="button">Browse gallery</a></p>
            </div>
          </div>
        </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>

JS:

$('#myCarousel').carousel();

Fiddle Demo

最佳答案

您的代码中的一切都很好,只需要在 css 下使用图像高度和宽度即可解决您的问题。

.carousel-inner > .item >img{
  min-height : 300px;
  max-height : 300px;
  width : 100%;
}

关于javascript - Bootstrap Carousel 未显示在页面上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36708453/

相关文章:

javascript - 使用videoJS的全屏分辨率问题

javascript - 定位 div #2

javascript - Jquery 函数在加载时被调用

javascript - 如果socketIO生成的ID是自动生成的,如何在两个用户之间建立通信?

javascript - 如何在文本框中插入值以选择选项

html - 如何在 Bootstrap 网格中将标题放在图像旁边?

twitter-bootstrap - 对具有相同数组名称(输入属性)的动态添加字段进行 Bootstrap 验证,例如名称 ="email[]"

jquery - 需要将 Bootstrap 菜单图标放在右侧

javascript - 视觉 : whitespace when carousel is sliding

jQuery 灯箱在 IE 中不起作用