基本信息
源码名称:BootStrap轮播图片示例源码
源码大小:0.49M
文件格式:.zip
开发语言:CSS
更新时间:2019-09-13
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
BootStrap图片轮播
BootStrap图片轮播
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
padding: 0px;
margin: 0px;
list-style: none;
}
.wrapper {
position: relative;
margin: 100px auto 0;
width: 400px;
height: 250px;
border: 1px solid #000;
overflow: hidden;
}
.wrapper .sliderPage {
position: absolute;
left: 0px;
top: 0px;
height: 250px;
width: 2000px;
}
.wrapper .sliderPage li {
width: 400px;
height: 250px;
float: left;
}
.wrapper .sliderPage li img {
width: 100%;
height: 100%;
}
.wrapper .btn {
position: absolute;
top: 50%;
margin-top: -20px;
width: 40px;
height: 40px;
color: #fff;
background: #000;
line-height: 40px;
text-align: center;
opacity: 0.1;
cursor: pointer;
}
.wrapper:hover .btn {
opacity: 0.7;
}
.wrapper .leftBtn {
left: 15px;
}
.wrapper .rightBtn {
right: 15px;
}
.wrapper .sliderIndex {
position: absolute;
width: 100%;
bottom: 15px;
text-align: center;
cursor: pointer;
}
.wrapper .sliderIndex span {
display: inline-block;
width: 8px;
height: 8px;
background: #ccc;
border-radius: 50%;
margin-right: 10px;
}
.wrapper .sliderIndex .active {
background: #f40;
}
</style>
</head>
<body>
<div class="wrapper">
<ul class="sliderPage">
<li>
<img src="cat1.jpg" alt="">
</li>
<li>
<img src="cat2.jpg" alt="">
</li>
<li>
<img src="cat3.jpg" alt="">
</li>
<li>
<img src="cat4.jpg" alt="">
</li>
<li>
<img src="cat1.jpg" alt="">
</li>
</ul>
<div class="btn leftBtn"><</div>
<div class=" btn rightBtn">></div>
<div class="sliderIndex">
<span class="active"></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
<script src="move.js"></script>
<script>
var timer = null;
var sliderPage = document.getElementsByClassName("sliderPage")[0];
var moveWidth = sliderPage.children[0].offsetWidth;
var num = sliderPage.children.length - 1;
var leftBtn = document.getElementsByClassName("leftBtn")[0];
var rightBtn = document.getElementsByClassName("rightBtn")[0];
var lock = true;
var index =0;
var oSpanArray = document.getElementsByClassName("sliderIndex")[0].getElementsByTagName("span");
leftBtn.onclick = function () {
autoMove("right->left");
}
rightBtn.onclick = function () {
autoMove("left->right");
}
for(var i = 0 ; i< oSpanArray.length;i ){
(function (myIndex){
oSpanArray[i].onclick = function(){
lock= false;
clearTimeout(timer);
startMove(sliderPage,{left:- index *moveWidth},function(){
lock= true;
timer = setTimeout(autoMove,1500);
changeIndex(index);
});
}
}(i))
}
//direction
//"left->right" 默认方向 //undefined //right
//"right->left" 点击left按钮
//31
function autoMove(direction) {
if (lock) {
lock = false;
clearTimeout(timer);
if (!direction || direction == "left->right") {
index ;
startMove(sliderPage, { left: sliderPage.offsetLeft - moveWidth }, function () {
if (sliderPage.offsetLeft == - num * moveWidth) {
index =0;
sliderPage.style.left = "0px";
}
timer = setTimeout(autoMove, 1500);
lock = true;
changeIndex(index)
});
}
}
else if (direction == "right->left") {
if (sliderPage.offsetLeft == 0) {
sliderPage.style.left == - num * moveWidth 'px';
index = num;
}
index--;
startMove(sliderPage, { left: sliderPage.offsetLeft moveWidth }, function () {
timer = setTimeout(autoMove, 1500);
lock= true;
changeIndex(index);
})
}
function changeIndex(_index){
for (var i = 0; i < oSpanArray.length; i ) {
oSpanArray[i].className = " ";
}
oSpanArray[_index].className = "active";
}
}
timer = setTimeout(autoMove, 1500)
</script>
</body>
</html>