2017-07-16 9 views
0

次と前のボタンは機能しなくなり、自動スクロールは機能しません。理由は分かりません。他の誰かが、その驚くほど明白な何かを見ますか?ブートストラップカルーセル自動スクロールと '次へ'と '前'が機能しない

JavaScriptファイルがないか、HTML自体に間違いがあるかどうかはわかりません。助けていただければ幸いです!

コード:

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> 
    <meta name="description" content="My cool website."> 
    <meta name="author" content="ThisGuy"> 
    <link rel="icon" href="img/quintin.ico"> 

    <title>test test</title> 

    <!-- Bootstrap core CSS --> 
    <link href="bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet"> 

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> 
    <link href="bootstrap-3.3.7-dist/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> 

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! --> 
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]--> 
    <script src="bootstrap-3.3.7-dist/js/ie-emulation-modes-warning.js"></script> 
    <script src="bootstrap-3.3.7-dist/js/carousel.js"></script> 

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries --> 
    <!--[if lt IE 9]> 
     <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script> 
     <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> 
    <![endif]--> 

    <!-- Custom styles for this template --> 
    <link href="carousel.css" rel="stylesheet"> 
    </head> 
<!-- NAVBAR 
================================================== --> 
    <body> 
    <div class="navbar-wrapper"> 
     <div class="container"> 

     <nav class="navbar navbar-inverse navbar-static-top"> 
      <div class="container"> 
      <div class="navbar-header"> 
       <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> 
       <span class="sr-only">Toggle navigation</span> 
       <span class="icon-bar"></span> 
       <span class="icon-bar"></span> 
       <span class="icon-bar"></span> 
       </button> 
       <a class="navbar-brand" href="#">Project name</a> 
      </div> 
      <div id="navbar" 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" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></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 role="separator" class="divider"></li> 
        <li class="dropdown-header">Nav header</li> 
        <li><a href="#">Separated link</a></li> 
        <li><a href="#">One more separated link</a></li> 
        </ul> 
       </li> 
       </ul> 
      </div> 
      </div> 
     </nav> 

     </div> 
    </div> 


    <!-- Carousel 
    ================================================== --> 
    <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"></li> 
     <li data-target="#myCarousel" data-slide-to="2"></li> 
     </ol> 
     <div class="carousel-inner" role="listbox"> 
     <div class="item active"> 
      <img class="first-slide" src="img/example1.jpg" 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="img/example2.jpg" 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="img/example3.jpg" 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><!-- /.carousel --> 


    <!-- Bootstrap core JavaScript 
    ================================================== --> 
    <!-- Placed at the end of the document so the pages load faster --> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
    <script>window.jQuery || document.write('<script src="bootstrap-3.3.7-dist/js/jquery.min.js"><\/script>')</script> 
    <script src="bootstrap-3.3.7-dist/dist/js/bootstrap.min.js"></script> 
    <!-- Just to make our placeholder images work. Don't actually copy the next line! --> 
    <script src="bootstrap-3.3.7-dist/js/holder.min.js"></script> 
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug --> 
    <script src="bootstrap-3.3.7-dist/js/ie10-viewport-bug-workaround.js"></script> 
    </body> 
</html> 
+0

ナビゲーションバーの[ドロップダウン]メニューも機能していないことに気付きました。私は、jQueryやJavascriptコードがどこかで見つからない可能性が高いと考えています。 また、これをドキュメントのブートストラップのサンプルコードから直接コピーしました。私はそれを自分のために適応させるつもりです。 – GBean

答えて

0

@GBean

あなたが誤ってロードされているbootstrap.min.js

<script src="bootstrap-3.3.7-dist/dist/js/bootstrap.min.js"></script> 

しかしbootstrap.min.jsは、私はあなたのコードをテストし、それが正常に動作している

<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script> - This one will work 

distのフォルダ内に存在しません。

+0

私はそれがそれほど小さくて刺激的であることを知っていました。あなたのワシの目をありがとう! – GBean

0

私はあなたがこのようにやろうと考えて:Check The Snippet

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 

 
<body> 
 

 
     <div class="container"> 
 

 
     <nav class="navbar navbar-inverse navbar-static-top" style=" 
 
    margin: auto;" > 
 
      <div class="container"> 
 
      <div class="navbar-header"> 
 
       <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> 
 
       <span class="sr-only">Toggle navigation</span> 
 
       <span class="icon-bar"></span> 
 
       <span class="icon-bar"></span> 
 
       <span class="icon-bar"></span> 
 
       </button> 
 
       <a class="navbar-brand" href="#">Project name</a> 
 
      </div> 
 
      <div id="navbar" 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" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></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 role="separator" class="divider"></li> 
 
        <li class="dropdown-header">Nav header</li> 
 
        <li><a href="#">Separated link</a></li> 
 
        <li><a href="#">One more separated link</a></li> 
 
        </ul> 
 
       </li> 
 
       </ul> 
 
      </div> 
 
      </div> 
 
     </nav> 
 

 
     </div> 
 

 

 

 

 

 
<div class="container"> 
 
    <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"></li> 
 
     <li data-target="#myCarousel" data-slide-to="2"></li> 
 
    </ol> 
 

 
    <!-- Wrapper for slides --> 
 
    <div class="carousel-inner"> 
 

 
     <div class="item active"> 
 
     <img src="https://www.w3schools.com/bootstrap/la.jpg" alt="Los Angeles" style="width:100%;"> 
 
     <div class="carousel-caption"> 
 
     <h3>Example headline.</h3> 
 
       <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 class="item"> 
 
     <img src="https://www.w3schools.com/bootstrap/chicago.jpg" alt="Chicago" style="width:100%;"> 
 
     <div class="carousel-caption"> 
 
     <h3>Another example headline.</h3> 
 
       <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 class="item"> 
 
     <img src="https://www.w3schools.com/bootstrap/ny.jpg" alt="New York" style="width:100%;"> 
 
     <div class="carousel-caption"> 
 
      <h3>One more for good measure.</h3> 
 
       <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> 
 

 
    <!-- Left and right controls --> 
 
    <a class="left carousel-control" href="#myCarousel" data-slide="prev"> 
 
     <span class="glyphicon glyphicon-chevron-left"></span> 
 
     <span class="sr-only">Previous</span> 
 
    </a> 
 
    <a class="right carousel-control" href="#myCarousel" data-slide="next"> 
 
     <span class="glyphicon glyphicon-chevron-right"></span> 
 
     <span class="sr-only">Next</span> 
 
    </a> 
 
    </div> 
 
</div> 
 
</body>

+0

**デモ:** https://www.w3schools.com/code/tryit.asp?filename=FHM73A5N297S –

関連する問題