轮播图的制做并不难,可是在实际开发中手写的轮播图作适配比较麻烦,在项目开发中前端大多都会使用bootstrap,那么使用bootstrap作出轮播图既快捷,适配性又高。
- 首先
bootstrap
的引用,由于它依赖jquery
,因此在HTML
中应该先引入jquery
(注意引入顺序)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
</body>
<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
</html>
复制代码
- 上述在线路径引入后,即可以直接在
HTML
中放入以下代码
<div class="carousel slide" id="carousel-example-generic" data-ride="carousel" data-interval="1500">
<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> </ol>
<div class="carousel-inner " id="hxp_lunbo">
<div class="item active "> <img src="src/common/image/photo/1 (1).jpg"> </div> <div class="item"> <img src="src/common/image/photo/1 (2).jpg"> </div> </div> <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left"></span> </a> <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-right"></span> </a> </div>
<!-- 上述中只须要更改图片的路径就能够轻松使用了 -->
复制代码