<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.max{
width: 500px;
height: 400px;
margin: 100px auto;
border: 1px solid red;
position: relative;
}
.max img{
width: 100%;
height: 100%;
}
.zuo,.you{
width: 50px;
height: 100px;
position: absolute;
font-size: 30px;
opacity: 0.8;
}
.zuo{
left: 0px;
top: 150px;
}
.you{
right: 0px;
top: 150px;
}
.anniu{
width: 50px;
height: 50px;
position: absolute;
font-size: 30px;
opacity: 0.8;
background-color: lightgray;
}
.max button:nth-of-type(3){
left: 40px;
bottom: 20px;
}
.max button:nth-of-type(4){
left: 130px;
bottom: 20px;
}
.max button:nth-of-type(5){
left: 220px;
bottom: 20px;
}
.max button:nth-of-type(6){
left: 310px;
bottom: 20px;
}
.max button:nth-of-type(7){
left: 400px;
bottom: 20px;
}
</style>
</head>
<body>
<div class="max">
<img src="./img/111.jpg" /> <!--图片地址 -->
<button class="zuo" οnclick="left()"><</button>
<button class="you" οnclick="right()">></button>
<button class="anniu" οnclick="dj(0)">1</button>
<button class="anniu" οnclick="dj(1)">2</button>
<button class="anniu" οnclick="dj(2)">3</button>
<button class="anniu" οnclick="dj(3)">4</button>
<button class="anniu" οnclick="dj(4)">5</button>
</div>
<button οnclick="qc()">清除计时器</button>
</body>
<script type="text/javascript">
//声明一个变量等会儿当下标用
var xx=0;
yanse();
//拿到图片
var img=document.querySelector("img");
//用一个数组装图片的名字
var arr=[111,222,333,444,555];
//点击左得方法
function left(){
//先让变量减减
xx--;
//判断当变量小于0得时候就让它变为4
if(xx<0){
xx=4;
}
//给图片换地址 地址里用到数组取值 从上面数组里拿图片名字
img.src="./img/"+arr[xx]+".jpg";
yanse();
}
//点击右得方法
function right(){
//先让变量加加
xx++;
//判断当变量大于4得时候就让它变为0
if(xx>4){
xx=0;
}
//给图片换地址 地址里用到数组取值 从上面数组里拿图片名字
img.src="./img/"+arr[xx]+".jpg";
yanse();
}
//点击单个按钮得方法
function dj(num){
//在上面绑定点击事件得时候 我们传参了几个数字 直接赋值给变量 就可以当下标用了
xx=num;
//给图片换地址 地址里用到数组取值 从上面数组里拿图片名字
img.src="./img/"+arr[xx]+".jpg";
yanse();
}
function yanse(){
var btn=document.querySelectorAll(".anniu");
// btn[0].style.backgroundColor="lightgray";
// btn[1].style.backgroundColor="lightgray";
// btn[2].style.backgroundColor="lightgray";
// btn[3].style.backgroundColor="lightgray";
// btn[4].style.backgroundColor="lightgray";
// for(var a=0;a<btn.length;a++){
// btn[a].style.backgroundColor="lightgray";
// }
btn.forEach(i=>{
i.style.backgroundColor="lightgray";
})
btn[xx].style.backgroundColor="pink";
}
var jsq=setInterval(right,1000)
var max=document.querySelector(".max");
// onmouseenter鼠标进入
// onmouseleave鼠标离开
max.οnmοuseenter=function(){
clearInterval(jsq)
}
max.οnmοuseleave=function(){
jsq=setInterval(right,1000)
}
// 清除计时器 必须用变量装 然后清除变量
// clearInterval(计时器)
// clearInterval(jsq)
// function qc(){
// clearInterval(jsq)
// }
// var shuzu=[23,4576,1243,567,3214,235253,4564564354];
// console.log(shuzu)
// for(var a=0;a<shuzu.length;a++){
// console.log(shuzu[a])
// }
// 数组.forEach(function(参数1){
// 参数1就是数组得每一位
// })
// shuzu.forEach(function(xx,yy){
// console.log(xx,yy)
// })
// shuzu.forEach((xx,yy)=>{
// console.log(xx,yy)
// })
</script>
</html>