Bootstrap 3: Full Slider not working. Uncaught TypeError: $(...).carousel is not a function
Bootstrap 3: Full Slider not working. Uncaught TypeError: $(...).carousel is not a function
我正在按照此网站上的模板创建主页:https://startbootstrap.com/template-overviews/full-slider/ 但我无法使其正常工作。我能够加载我所有的图像,但是当我预览页面时,每个图像的 headers 重叠,按钮不起作用并且图片显示不正确(我看到我的第一张图片,然后是页脚,然后我的另外两张图片就在页脚之后)。
这是我的索引:
<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>
这是我的滑块:
<!-- 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>
在页脚之后,我为滑块设置了以下 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>
这是我的 starter-template 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;
}
这里是 full-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 或更高版本存在依赖关系
我正在按照此网站上的模板创建主页:https://startbootstrap.com/template-overviews/full-slider/ 但我无法使其正常工作。我能够加载我所有的图像,但是当我预览页面时,每个图像的 headers 重叠,按钮不起作用并且图片显示不正确(我看到我的第一张图片,然后是页脚,然后我的另外两张图片就在页脚之后)。
这是我的索引:
<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>
这是我的滑块:
<!-- 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>
在页脚之后,我为滑块设置了以下 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>
这是我的 starter-template 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;
}
这里是 full-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 或更高版本存在依赖关系