js轮播图出不来效果,想实现那种慢慢往左滑动的效果,不是那种突然就换图片那种,是不是定时器里边再套一个定时器,有没有大牛帮我改一下,感激不尽!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
list-style-type: none;
}
.box {
position: relative;
width: 600px;
height: 400px;
margin: 100px auto;
border: 1px solid #000;
overflow: hidden;
}
.box ul {
position: absolute;
width: 2400px;
}
.box li {
float: left;
font-size: 0;
}
.circle {
position: absolute;
bottom: 10px;
left: 0;
width: 100%;
font-size: 0;
text-align: center;
}
.circle span {
display: inline-block;
width: 20px;
height: 20px;
margin: 2px;
border-radius: 100%;
background-color: rgba(0,0,0,.5);
}
.box button {
position: absolute;
width: 40px;
height: 50px;
top: 50%;
margin-top: -25px;
font-size: 30px;
color: #fff;
border: 0;
background-color: rgba(0,0,0,.5);
}
button:nth-of-type(1) {
left: 0;
}
button:nth-of-type(2) {
right: 0;
}
span.active {
background-color: rgba(255,0,0,.5);
}
</style>
</head>
<body>
<div class="box">
<ul>
<li><img src="./img/t1.png" alt=""></li>
<li><img src="./img/t2.png" alt=""></li>
<li><img src="./img/t3.png" alt=""></li>
<li><img src="./img/t4.png" alt=""></li>
<li><img src="./img/t1.png" alt=""></li>
</ul>
<div class="circle">
<span class="active"></span>
<span></span>
<span></span>
<span></span>
</div>
<button><</button> <button>></button>
</div>
<script>
var btn = document.querySelectorAll('button');
var ul = document.querySelector('ul');
var span = document.querySelectorAll('span');
var bw =parseInt(getComputedStyle(document.querySelector('.box')).width) ;
console.log(bw);
var n = 0 ;
setInterval(function () {
n++;
if (n == 4) {
n = 0;
}
t= setInterval(function () {
var l = parseInt(getComputedStyle(ul).left) - 20;
if (l <= n*-bw) {
l=n*-bw
clearInterval(t);
}
ul.style.left = l + 'px';
}, 70);
}, 2000);
</script>
</body>
</html>