<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>无缝滚动</title>
</head>
<style type="text/css">
.box{
width: 600px;
height: 300px;
margin: 0 auto;
overflow: hidden;
position: relative;
border: 2px solid orange;
}
.box-border{
width: 1800px;
height: 300px;
position: absolute;
box-sizing: border-box;
display: flex;
}
.box-border>div{
height: 300px;
width: 300px;
display: flex;
background: #34495E;
color: white;
justify-content: center;
align-items: center;
box-sizing: border-box;
border: 1px solid #03A9F4;
}
</style>
<body>
<div class="box">
<div class="box-border" id="border">
<div >1</div>
<div >2</div>
<div >3</div>
<div >4</div>
<div >1</div>
<div >2</div>
</div>
</div>
</body>
<script type="text/javascript">
let dom = document.getElementById("border");
let time = 0;
setInterval(()=>{
time--;
if(time == -1200){
time = 0
}
dom.style.left = time+"px";
},1)
</script>
</html>
JS 超简单的无缝滚动案例
于 2022-03-27 23:36:56 首次发布