Bootstrap 引导转盘内部“自动播放”

flseospp  于 2023-02-27  发布在  Bootstrap
关注(0)|答案(4)|浏览(177)

有人能帮我吗?我知道这里有一些错误。为什么我必须在页眉的末尾和页面的底部链接bootstrap.min.js。我试过一次使用一个,但它不起作用。下一件事是我希望当我加载页面和单击控制器时,carousel启动;而不仅仅是当我点击控制器的时候。

<head>
        <title>The James Baldwin School</title>
        <link href="Framework/css/bootstrap.css" rel="stylesheet" type="text/css">
        <link href="Main.css" rel="stylesheet" type="text/css">
    </head>

    <body>
        <header>
        <div class="navbar-wrapper">
  <div class="container">
    <div id="navtop" class="navbar navbar-inverse navbar-static-top">

        <div class="navbar-header">
        <a class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </a>
        <a class="navbar-brand" href="#">The James Baldwin School</a>
        </div>
        <div class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li class="active"><a href="#">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">Parents <b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li class="divider"></li>
                <li><a href="#">Separated link</a></li>
                <li><a href="#">One more separated link</a></li>
              </ul>
            </li>

            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">Students <b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li class="divider"></li>
                <li><a href="#">Separated link</a></li>
                <li><a href="#">One more separated link</a></li>
              </ul>
            </li>

            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">Teachers <b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li class="divider"></li>
                <li><a href="#">Separated link</a></li>
                <li><a href="#">One more separated link</a></li>
              </ul>
            </li>
          </ul>
        </div>


    </div>
  </div><!-- /container -->
</div><!-- /navbar wrapper -->

        <!--- Javascript Bootstrap --->
        <script src="Framework/js/bootstrap.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</header>

<!-- Carousel
================================================== -->
<div id="myCarousel" class="carousel slide">
  <!-- Indicators -->
  <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="http://1.bp.blogspot.com/-BUrT0CP-6nQ/U1prUuv6VjI/AAAAAAAAFbY/a6PUNgNhSWM/s1600/1500x500-New-York-Skyline-Twitter-Header0017.jpg" style="width:100%" class="img-responsive">
      <div class="container">
        <div class="carousel-caption">
          <h1>Bootstrap 3 Carousel</h1>
          <p>Pictures slide with overlapping words</p>
          <p><a class="btn btn-lg btn-primary" href="http://getbootstrap.com">Learn More</a>
        </p>
        </div>
      </div>
    </div>
    <div class="item">
      <img src="http://1.bp.blogspot.com/-jBZKbiHI_2U/U1pszgzFAbI/AAAAAAAAFcI/8xrxWuBse9o/s1600/1500x500-New-York-Skyline-Twitter-Header0024.jpg" class="img-responsive">
      <div class="container">
        <div class="carousel-caption">
          <h1>Each Slide can be different</h1>
          <p>I just need some one to pick the pictures and words</p>
          <p><a class="btn btn-large btn-primary" href="#">Learn more</a></p>
        </div>
      </div>
    </div>
    <div class="item">
      <img src="http://mooxidesign.com/wp-content/uploads/2014/04/New-york-1500x500.jpg" class="img-responsive">
      <div class="container">
        <div class="carousel-caption">
          <h1>Percentage-based sizing</h1>
          <p>This Site is fully responsive and adjusts to the size of the browser your using. Meaning that it looks great on smart-phones</p>
          <p><a class="btn btn-large btn-primary" href="#">Browse gallery</a></p>
        </div>
      </div>
    </div>
  </div>
  <!-- Controls -->
  <a class="left carousel-control" href="#myCarousel" data-slide="prev">
    <span class="icon-prev"></span>
  </a>
  <a class="right carousel-control" href="#myCarousel" data-slide="next">
    <span class="icon-next"></span>
  </a>  
</div>       
<!-- /.carousel -->

<!-- Marketing messaging and featurettes
================================================== -->
<!-- Wrap the rest of the page in another container to center all the content. -->

<div class="container marketing">

  <!-- Three columns of text below the carousel -->
<div id="about">
  <div class="row">
    <div class="col-md-4 text-center">
      <img class="img-circle" src="http://placehold.it/140x140">
      <h2>Brady Smith</h2>
      <p>Principal Co-Director</p>
      <p><a class="btn btn-default" href="#">View details »</a></p>
    </div>
    <div class="col-md-4 text-center">
      <img class="img-circle" src="http://placehold.it/140x140">
      <h2>Josh Heisler</h2>
      <p>Teacher Co-Director</p>
      <p><a class="btn btn-default" href="#">View details »</a></p>
    </div>
    <div class="col-md-4 text-center">
      <img class="img-circle" src="http://placehold.it/140x140">
      <h2>Christine Olsen</h2>
      <p>Admissions</p>
      <p><a class="btn btn-default" href="#">View details »</a></p>
    </div>
  </div><!-- /.row -->
</div>

  <!-- START THE FEATURETTES -->


  <!-- /END THE FEATURETTES -->

  <!-- FOOTER -->
  <footer>
    <p class="pull-right"><a href="#">Back to top</a></p>
    <p>This site was created by Isaac Perez. · <a href="http://www.google.com">Check it out</a></p>
  </footer>

  </div><!-- /.container -->

</body>
        <script src="Framework/js/bootstrap.min.js"></script>
        <script src="Framework/js/jquery-2.1.3.min.js"></script>
        <script type="text/javascript">// <![CDATA[
        var $ = jQuery.noConflict(); $(document).ready(function()  { $('#myCarousel').carousel({ interval: 3000, cycle: true }); });
        // ]]></script>
</html>
nzk0hqpo

nzk0hqpo1#

我刚刚设置了一个Fiddle,其中包含示例的carousel、jQuery版本2.1.3、bootstrap.js和bootstrap.css作为外部资源,以及用于初始化carousel的脚本

$('#myCarousel').carousel({
  interval: 3000,
  cycle: true
});

并且它正在工作--当页面加载并且控制器也在工作时它就开始了。它不工作可能是在jQuery之前加载 Bootstrap 的问题-- jQuery必须在 Bootstrap 之前包含。要检查是否是这种情况,请查看是否有任何错误/控制台消息,如“错误:Bootstrap的JavaScript需要jQuery”“。此外,您还包括2个不同的jQuery版本- 1.11.1和2.1.3。如果不需要,例如,对于一些依赖于旧jQuery版本的插件,尝试只加载最新版本。
另外,你把script标签放在结束body和html标签之间,这些标签可以工作,但是是无效的--参见link, script tags between and 了解细节。
作为使用不同jQuery版本的参考(如果确实需要),您可以选中http://api.jquery.com/jquery.noconflict/

o75abkj4

o75abkj42#

你可以通过HTML中的data-interval标签来完成,将它插入<div id="myCarousel" class="carousel slide">中,看起来像这样:

<div id="myCarousel" class="carousel slide" data-interval="3000">

3000的值可以调整为较高的数值以降低速度,也可以调整为较低的数值以提高速度。

xytpbqjk

xytpbqjk3#

在包含的carousel div中添加自定义属性data-ride="carousel"。您可以选择添加data-interval="5000"以更改滑块更改持续时间(毫秒)。

bksxznpy

bksxznpy4#

这适用于Bootstrap v5.3。请阅读https://getbootstrap.com/docs/5.3/components/carousel/#methods
在carousel div中,将data-bs-ride设置为“carousel”。

<div id="carouselExample" class="carousel slide" data-bs-ride="carousel"> </id>

然后,body标记的所有最后部分写入以下代码:

<body>
      ...
        <script>
        const myCarouselElement = document.querySelector('#carouselExample')

        const carousel = new bootstrap.Carousel(myCarouselElement, {
           interval: 2000,
           touch: false
          })
        </script> 
    </body>

相关问题