首页 技术 正文
技术 2022年11月7日
0 收藏 688 点赞 657 浏览 3440 个字

前期准备:

1.jquery.js。

2.bootstrap的carousel.js。

3.bootstrap.css。

如果大家不知道在哪下载,可以联系小颖,小颖把这些js和css可以发送给你。

一起来看代码吧:

小颖画的页面比较丑,希望大家不要介意哦嘻嘻

效果图:

利用bootstrap的carousel.js实现轮播图动画

html+js:

<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<title>my love-首页</title>
<link rel="stylesheet" href="css/bootstrap.css" rel="external nofollow" >
<link rel="stylesheet" href="css/index.css" rel="external nofollow" >
<link href="favicon.ico" rel="external nofollow" rel="shortcut icon" />
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/carousel.js" type="text/javascript"></script>
</head><body>
<div class="index-content">
<div class="index-header">
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="javascript:void(0)" rel="external nofollow" >首页</a>
</div>
<div>
<ul class="nav navbar-nav">
<li class="active"><a href="#section1" rel="external nofollow" class="con">向日葵花</a></li>
<li><a href="#section2" rel="external nofollow" class="con">萌萌哒的狗狗</a></li>
<li><a href="#section3" rel="external nofollow" class="con">好吃哒</a></li>
</ul>
</div>
</div>
</nav>
</div>
<div class="index-body">
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="data:image/indexOne.jpg" alt="向日葵" class="images">
</div>
<div class="item">
<img src="data:image/indexTwo.jpg" alt="萌萌哒狗狗" class="images">
</div>
<div class="item">
<img src="data:image/indexThree.jpg" alt="好吃哒" class="images">
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" rel="external nofollow" rel="external nofollow" 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="#carousel-example-generic" rel="external nofollow" rel="external nofollow" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
<div class="index-footer">
<div class="footer-centent">
Copyright ©2016 爱喝酸奶的吃货
</div>
</div>
</div>
<script type="text/javascript">
$(function() {
$(".navbar-nav li").each(function(index) {
$(this).click(function() {
$("li.active").removeClass("active"); //注意这里
$(this).addClass("active"); //注意这里
$(".carousel-inner div.active").removeClass("active");
$(".carousel-inner div").eq(index).addClass("active");
});
});
window.setInterval(function() {
$(".carousel-inner div").each(function(index) {
if ($(this).hasClass("active")) {
$(".navbar-nav li.active").removeClass("active");
$(".navbar-nav li").eq(index).addClass("active");
}
});
}, 100);
});
</script>
</body></html>

index.css

.container-fluid {
padding-left: 200px;
}.navbar-default {
background-color: #308dca;
}.navbar-brand {
font-size: 34px;
height: 70px;
}.navbar-nav>li>a {
font-size: 19px;
}.navbar-default .navbar-brand, .navbar-default .navbar-nav>li>a, .navbar-default .navbar-nav>li>a:hover, .navbar-default .navbar-nav>li>a:focus {
color: #fff;
}.navbar-brand, .navbar-nav>li>a {
line-height: 40px;
}.navbar-default .navbar-nav>.active>a, .navbar-default .navbar-nav>.active>a:hover, .navbar-default .navbar-nav>.active>a:focus {
color: #fff;
background-color: #2276bf;
}.index-body {
margin: 0 auto;
}.carousel-inner {
height: 490px;
}.index-body, .images {
width: 900px;
}.index-footer {
margin-top: 20px;
color: #fff;
background-color: #2276bf;
}.footer-centent {
width: 300px;
font-size: 20px;
line-height: 55px;
margin: 0 auto;
height: 60px;
}

大家在自己设计demo的时候注意下,class为index-body的div和img的宽度要设置一样,否则会出现以下情况:

利用bootstrap的carousel.js实现轮播图动画

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,505
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844