<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>轮播图</title>
<style>
* {
padding: 0;
margin: 0;
list-style: none;
}
.box1 {
position: relative;
width: 790px;
height: 340px;
margin: 100px auto;
}
.box1 li {
position: absolute;
display: none;
}
.box1 li:first-child {
display: block;
}
.arrow {
display: none;
}
.box1:hover .arrow {
display: block;
}
.arrow-left,
.arrow-right {
width: 30px;
height: 60px;
background-color: rgba(0, 0, 0, 0.1);
/*background-color: #e53935;*/
position: absolute;
top: 50%;
margin-top: -30px;
cursor: pointer;
text-align: center;
line-height: 60px;
color: #fff;
font-size: 30px;
}
.arrow-left {
left: 0;
}
.arrow-right {
right: 0
}
.arrow-left:hover,
.arrow-right:hover {
background-color: rgba(0, 0, 0, .5);
}
.circles {
position: absolute;
left: 20px;
bottom: 20px;
}
.circles > i {
width: 12px;
height: 12px;
border: 2px solid #fff;
border-radius: 50%;
display: inline-block;
margin-left: 8px;
}
.circles > i.on {
background-color: #fff;
}
</style>
</head>
<body>
<script src="../day14/jquery-3.0.0.js"></script>
<div class="box1">
<ul class="picbox">
<li><a href="#"><img src="img/1.jpg"></a></li>
<li><a href="#"><img src="img/2.jpg"></a></li>
<li><a href="#"><img src="img/3.jpg"></a></li>
<li><a href="#"><img src="img/4.jpg"></a></li>
<li><a href="#"><img src="img/5.jpg"></a></li>
<li><a href="#"><img src="img/6.jpg"></a></li>
<li><a href="#"><img src="img/7.jpg"></a></li>
<li><a href="#"><img src="img/8.jpg"></a></li>
</ul>
<div class="arrow">a
<span class="arrow-left"><</span>
<span class="arrow-right">></span>
</div>
<div class="circles">
<i class="on" a="0"></i>
<i a="1"></i>
<i a="2"></i>
<i a="3"></i>
<i a="4"></i>
<i a="5"></i>
<i a="6"></i>
<i a="7"></i>
</div>
</div>
<script>
$(function () {
var $lookbox = $('.box1');
var index = 0;
$('.arrow-right').click(function () {
MyToogle(1);
buttonshow()
});
$('.arrow-left').click(function () {
MyToogle(0);
buttonshow()
});
function MyToogle(flag) {
if (flag === 0) {
index--;
if (index === -1) {
index = 7
}
}
else {
index++;
if (index === 8) {
index = 0;
}
}
$('.picbox').find('li').eq(index).fadeIn(1000).siblings().fadeOut(1000)
}
function play() {
timer = setInterval(function () {
MyToogle(1);
buttonshow()
}, 1000)
}
play();
$lookbox.mouseover(function () {
clearInterval(timer)
});
$lookbox.mouseout(function () {
play()
});
function buttonshow() {
$('.circles>i').removeClass('on');
$('.circles>i').eq(index).addClass('on')
}
$('.circles>i').mouseover(function () {
var newindex = $(this).attr('a');
$('.circles>i').removeClass('on');
$(this).addClass('on');
$('.picbox>li').eq(newindex).fadeIn(300).siblings().fadeOut(300)
})
})
</script>
</body>
</html>