下面代码可以直接拷贝运行,样式和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>自制轮播</title>
</head>
<body>
<div class="content">
<div class="sub1 p1" id="d1"></div>
<div class="sub2 p2" id="d2"></div>
<div class="sub3 p3" id="d3"></div>
<div class="sub4 p4" id="d4"></div>
</div>
<div class="swiper-status">
<div class="po1" id="p1"></div>
<div class="po2" id="p2"></div>
<div class="po3" id="p3"></div>
<div class="po4" id="p4"></div>
</div> id="p2"
<button οnclick="test()"> 测试移动</button>
</body>
<style>
body{
/* perspective: 100px; */
}
.swiper-status{
width: 110px;
height: 16px;
margin: 5px auto;
/* background-color: red; */
display: flex;
justify-content: space-between;
}
.content{
/* transform-style: preserve-3d; */
position: relative;
height: 309px;
width: 750px;
background-color: pink;
margin: 10px auto;
overflow: hidden;
}
.content .stus{
position: absolute;
width: 110px;
height: 15px;
z-index: 5;
background-color: #fff;
}
.content div{
position: absolute;
height: 80%;
width: 616px;
/* top: 10%; */
/* margin: auto; */
left: 68px;
transition: all 0.5s;
}
div.sub1{
/* transform:translateZ(100px); */
background-color: green;
}
div.p1{
left: -582px;
height: 80%;
top: 10%;
z-index: 1;
}
div.sub2{
background-color: yellowgreen;
}
div.p2{
/* left: 716px;
height: 80%;
top: 10%; */
transform: scaleY(3.25);
z-index: 1;
}
div.sub3{
background-color: black;
}
div.p3{
left: 716px;
height: 80%;
top: 10%;
z-index: 1;
}
div.sub4{
background-color: red;
}
div.p4{
/* visibility: hidden; */
left: 1466px;
height: 80%;
top: 10%;
z-index: 0;
transition: none;
}
.swiper-status div{
height: 16px;
width: 16px;
background-color: #C9C9C9;
border-radius: 50%;
}
div.po1{
width: 45px;
background-color: #FF8100;
border-radius: 7px;
}
</style>
<script>
var d1=document.getElementById("d1")
window.οnlοad=function(){
var d1=document.getElementById("d1")
var d2=document.getElementById("d1")
var d3=document.getElementById("d1")
var d4=document.getElementById("d1")
}
function test(){
var d1=document.getElementById("d1")
var d2=document.getElementById("d2")
var d3=document.getElementById("d3")
var d4=document.getElementById("d4")
var p1=document.getElementById("p1")
var p2=document.getElementById("p2")
var p3=document.getElementById("p3")
var p4=document.getElementById("p4")
console.log("按钮被点击")
var i=1,k1=1,k2=2,k3=3,k4=4
console.log("i","k1","k2","k3","k4")
// while(true){
//
// }
setInterval(() => {
i=i>4?1:i
k1=isZero(k1-1)
k2=isZero(k2-1)
k3=isZero(k3-1)
k4=isZero(k4-1)
console.log(i,k1,k2,k3,k4)
d1.setAttribute("class", "sub1 p"+k1);
d2.setAttribute("class", "sub2 p"+k2);
d3.setAttribute("class", "sub3 p"+k3);
d4.setAttribute("class", "sub4 p"+k4);
// sleep(1000)
p1.setAttribute("class", "sub1 po"+k1);
p2.setAttribute("class", "sub2 po"+k2);
p3.setAttribute("class", "sub3 po"+k3);
p4.setAttribute("class", "sub4 po"+k4);
i++
}, 1000);
}
function isZero(k){
return k<=0?4:k
}
var sleep = function(time) {
var startTime = new Date().getTime() + parseInt(time, 10);
while(new Date().getTime() < startTime) {}
};
</script>
</html>