Bootstrap轮播不会滚动/加载

时间:2017-12-19 07:11:58

标签: javascript jquery html twitter-bootstrap-3 carousel

我一直在浏览电路板和论坛一段时间,试图弄清楚为什么我的旋转木马不会加载/滚动。我读到了必须链接到popper.js文件,阅读有关在引导之前加载jquery和popper以及其他一些其他问题。一旦我开始加载popper.js,我的控制台就没有错误。任何人都可以在我的HTML中看到一个问题,并告诉我为什么旋转木马不会自动滚动或使用glyphicons?当我点击旋转木马时,它没有做任何事情,给我任何错误或者在我加载popper js文件之前去#theCarousel。我感谢任何人都能给予的帮助。

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<!-- If IE use the latest rendering engine -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<!-- Set the page to the width of the device and set the zoon level -->
<meta name="viewport" content="width = device-width, initial-scale = 1">

<title>Bootstrap Tutorial</title>

<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<link href="https://fonts.googleapis.com/css?family=Pacifico" rel='stylesheet' type='text/css'>

<style type="text/css">

/* Carousel Styling */
.slide1{
    background-image: url('./img/bkgrnd1.jpeg');
    height: 500px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
}
.slide2{
    background-image: url('./img/bkgrnd2.jpg');
    height: 500px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
}
.slide3{
    background-image: url('./img/bkgrnd3.jpg');
    height: 500px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
}
.slide1{
    background-image: url('./img/bkgrnd4.jpeg');
    height: 500px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
}
.carousel-caption h1{
    font-size: 5.4em;
    font-family: 'Pacifico', cursive;
    padding-bottom: .4em;
}
.carousel-caption p{
    font-size: 2em;
}
</style>

<body>

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

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

    <div class="carousel-inner">
        <div class="item active">
            <div class="slide1"></div>
            <div class="carousel-caption">
                <h1>Amazing Backgrounds</h1>
                <p>Thousands of Backgrounds for Free</p>
                <p><a href="#" class="btn btn-primary btn-sm">Get them now!</a></p>
            </div>
        </div>
        <div class="item">
            <div class="slide2"></div>
            <div class="carousel-caption">
                <h1>This is SLIDE TWOO</h1>
                <p>Thousands of SLIDE TWOS for Free</p>
            </div>
        </div>
        <div class="item">
            <div class="slide3"></div>
            <div class="carousel-caption">
                <h1>Amazing ILLUSIONS</h1>
                <p>Thousands of SLIDE THREES for Free</p>
            </div>
        </div>
        <div class="item">
            <div class="slide4"></div>
            <div class="carousel-caption">
                <h1>Amazing COLORS</h1>
                <p>Thousands of SLIDE FOURS for Free</p>
                <p><a href="#" class="btn btn-primary btn-sm">BUTTON 4!</a></p>
            </div>
        </div>
    </div>

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

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="/js/bootstrap.min.js"></script>


</body>
</html>

2 个答案:

答案 0 :(得分:2)

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>


<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

把所有这些放在旋转木马的顶部因为旋转木马需要这个是完整的答案我希望它会帮助你

    <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<!-- If IE use the latest rendering engine -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">

<!-- Set the page to the width of the device and set the zoon level -->
<meta name="viewport" content="width = device-width, initial-scale = 1">

<title>Bootstrap Tutorial</title>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>


<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

<link href="https://fonts.googleapis.com/css?family=Pacifico" rel='stylesheet' type='text/css'>

<style type="text/css">

/* Carousel Styling */
.slide1{
    background-image: url('https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/68dd54ca-60cf-4ef7-898b-26d7cbe48ec7/10-dithering-opt.jpg');
    height: 500px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
}
.slide2{
    background-image: url('https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/68dd54ca-60cf-4ef7-898b-26d7cbe48ec7/10-dithering-opt.jpg');
    height: 500px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
}
.slide3{
    background-image: url('https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/68dd54ca-60cf-4ef7-898b-26d7cbe48ec7/10-dithering-opt.jpg');
    height: 500px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
}
.slide1{
    background-image: url('https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/68dd54ca-60cf-4ef7-898b-26d7cbe48ec7/10-dithering-opt.jpg');
    height: 500px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
}
.slide4{
    background-image: url('https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/68dd54ca-60cf-4ef7-898b-26d7cbe48ec7/10-dithering-opt.jpg');
    height: 500px;
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
}
.carousel-caption h1{
    font-size: 5.4em;
    font-family: 'Pacifico', cursive;
    padding-bottom: .4em;
}
.carousel-caption p{
    font-size: 2em;
}
</style>

<body>

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

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

    <div class="carousel-inner">
        <div class="item active">
            <div class="slide1"></div>
            <div class="carousel-caption">
                <h1>Amazing Backgrounds</h1>
                <p>Thousands of Backgrounds for Free</p>
                <p><a href="#" class="btn btn-primary btn-sm">Get them now!</a></p>
            </div>
        </div>
        <div class="item">
            <div class="slide2"></div>
            <div class="carousel-caption">
                <h1>This is SLIDE TWOO</h1>
                <p>Thousands of SLIDE TWOS for Free</p>
            </div>
        </div>
        <div class="item">
            <div class="slide3"></div>
            <div class="carousel-caption">
                <h1>Amazing ILLUSIONS</h1>
                <p>Thousands of SLIDE THREES for Free</p>
            </div>
        </div>
        <div class="item">
            <div class="slide4"></div>
            <div class="carousel-caption">
                <h1>Amazing COLORS</h1>
                <p>Thousands of SLIDE FOURS for Free</p>
                <p><a href="#" class="btn btn-primary btn-sm">BUTTON 4!</a></p>
            </div>
        </div>
    </div>

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



</body>
</html>

答案 1 :(得分:0)

这会对你有所帮助。 http://jsfiddle.net/r2wLz6xr/431/

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>

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

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

<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
 <div class="item active">
  <div class="slide1"></div>
        <div class="carousel-caption">
            <h1>Amazing Backgrounds</h1>
            <p>Thousands of Backgrounds for Free</p>
            <p><a href="#" class="btn btn-primary btn-sm">Get them now!</a></p>
        </div>
</div>
<div class="item">
  <div class="slide2"></div>
        <div class="carousel-caption">
            <h1>This is SLIDE TWOO</h1>
            <p>Thousands of SLIDE TWOS for Free</p>
        </div>
</div>
<div class="item">
  <div class="slide3"></div>
        <div class="carousel-caption">
            <h1>Amazing ILLUSIONS</h1>
            <p>Thousands of SLIDE THREES for Free</p>
        </div>
</div> 
<div class="item">
<div class="slide4"></div>
        <div class="carousel-caption">
            <h1>Amazing COLORS</h1>
            <p>Thousands of SLIDE FOURS for Free</p>
            <p><a href="#" class="btn btn-primary btn-sm">BUTTON 4!</a></p>
        </div>
        </div>
 </div>
<!-- Controls -->
<a class="left carousel-control" href="#theCarousel" 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="#theCarousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>

CSS

/* Carousel Styling */
.slide1{
background-image: url('http://via.placeholder.com/700x700');
height: 500px;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.slide2{
background-image: url('http://via.placeholder.com/700x700');
height: 500px;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.slide3{
background-image: url('http://via.placeholder.com/700x700');
height: 500px;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.slide4{
background-image: url('http://via.placeholder.com/700x700');
height: 500px;
background-repeat: no-repeat;
background-position: center;
background-size: cover;
}
.carousel-caption h1{
font-size: 5.4em;
font-family: 'Pacifico', cursive;
padding-bottom: .4em;
}
.carousel-caption p{
font-size: 2em;
}