<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
#big{
width: 700px;
height: 420px;
overflow: hidden;
position: relative;
}
#container{
width: 100%;
height: 100%;
position: absolute;
left: -700px;
white-space: nowrap;/* 不换行显示 */
}
.item{
width: 100%;
height: 100%;
background-repeat: no-repeat;
background-size: 100% 100%;
display: inline-block;
margin: -2px;
}
</style>
</head>
<body>
<div id="big">
<div id="container">
<div class="item" style="background-image: url(./img/4.jpg)"></div>
<div class="item" style="background-image: url(./img/1.jpg)"></div>
<div class="item" style="background-image: url(./img/2.jpg)"></div>
<div class="item" style="background-image: url(./img/3.jpg)"></div>
<div class="item" style="background-image: url(./img/4.jpg)"></div>
<div class="item" style="background-image: url(./img/1.jpg)"></div>
</div>
</div>
<script>
// 第一次显示 1*700px 第二次移动2*width
var big = document.getElementById("big");
var container = document.getElementById("container");
var length = container.children.length-2;
var index = 1;//索引
run=()=>{
var myInterval = setInterval(()=>{
if(index==length+1){
// container.clientWidth
container.style.left = -index*big.clientWidth+"px";
container.style.transition="left 1s";
clearInterval(myInterval);
setTimeout(()=>{
index =1;
container.style.left = -big.clientWidth+"px";
container.style.transition="left 0s";
console.log(index);
},1000);
run();
}else{
index++;
container.style.left = -index*big.clientWidth+"px";
container.style.transition="left 1s";
}
},2000);
}
run();
</script>
</body>
</html>
本文来自博客园,作者:{潇潇消消气},转载请注明原文链接:{https://www.cnblogs.com/xiaoxiaodeboke/}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix