我正在按照本网站上的模板创建主页:https://startbootstrap.com/template-overviews/full-slider/但我无法让它正常工作。我可以加载我所有的图片,但是当我预览页面时,每张图片的标题重叠,按钮不起作用,图片显示不正确(我看到我的第一张图片,然后是页脚,然后是我的另外两张图片就在页脚之后)。
这是我的索引:
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="risorse/bootstrap-3.3.7-dist/css/bootstrap.min.css">
<link href="risorse/stili/starter-template.css" rel="stylesheet">
<link href="risorse/stili/full-slider.css" rel="stylesheet">
</head>
这是我的 slider :
<!-- Full Page Image Background Carousel Header -->
<header 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>
<!-- Wrapper for Slides -->
<div class="carousel-inner">
<div class="item active">
<!-- Set the first background image using inline CSS below. -->
<div class="fill" style="background-image:url('risorse/immagini/slider_1.jpg');"></div>
<h2>Chiesa San Marco - Baucina</h2>
</div>
</div>
<div class="item">
<!-- Set the second background image using inline CSS below. -->
<div class="fill" style="background-image:url('risorse/immagini/slider_2.jpg');"></div>
<div class="carousel-caption">
<h2>Mostra Expo Canina 2016 - Baucina</h2>
</div>
</div>
<div class="item">
<!-- Set the third background image using inline CSS below. -->
<div class="fill" style="background-image:url('risorse/immagini/slider_3.jpg');"></div>
<div class="carousel-caption">
<h2>Paesaggio Siciliano</h2>
</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>
</header>
在页脚之后,我有以下用于 slider 的 jquery 函数:
<script src="risorse/js/jquery.js"></script>
<script src="risorse/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="risorse/jquery/jquery-3.1.1.min.js"><\/script>')</script>
<script>
$('.carousel').carousel({
interval: 5000 //changes the speed
})
</script>
这是我的入门模板 CSS:
html {
position: relative;
height: 100%;
}
body {
padding-top: 50px;
/* Margin bottom by footer height */
margin-bottom: 60px;
height: 100%;
}
.starter-template {
padding: 40px 15px;
text-align: center;
}
.footer {
position: relative;
bottom: 0;
width: 100%;
/* Set the fixed height of the footer here */
height: 60px;
background-color: black;
}
.footer p {
margin: 10px 0;
}
这是完整的 slider CSS:
.carousel,
.item,
.active {
height: 100%;
}
.carousel-inner {
height: 100%;
}
/* Background images are set within the HTML using inline CSS, not here */
.fill {
width: 100%;
height: 100%;
background-position: center;
-webkit-background-size: cover;
-moz-background-size: cover;
background-size: cover;
-o-background-size: cover;
}
我检查了控制台并收到此错误:Uncaught TypeError: $(...).carousel 不是函数。我正在尝试解决方案,但似乎还没有任何效果。
最佳答案
尝试只加载 jquery 库一次。 在 bootstrap 之前只加载一个版本的 jquery,对于 Bootstrap 3,我认为对 jQuery 的依赖设置为 1.9.0 或更高版本
关于jquery - Bootstrap 3 : Full Slider not working. Uncaught TypeError : $(. ..).carousel 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41922618/