<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#wrap{
width: 500px;
height: 300px;
overflow: hidden;
position: relative;
margin: 0 auto;
}
#box{
width: 500%;
height: 100%;
position: absolute;
left: 0;
transition: all 1s linear;
}
#box div {
width: 500px;
height: 300px;
float: left;
background-color: #7A8FD9;
color: white;
font-size: 50px;
line-height: 300px;
text-align: center;
}
</style>
</head>
<body>
<div id="wrap">
<div id="box">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</div>
</body>
<script>
//JS版本轮播图
setInterval(
function(){
//让box向左移动每次移动500px
var l = box.offsetLeft;
l -= 500;
if (l < -1000) {
l = 0 ;
}
box.style.left = l + "px";
},2000)
</script>
</html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#wrap{
width: 500px;
height: 300px;
overflow: hidden;
position: relative;
margin: 0 auto;
}
#box{
width: 500%;
height: 100%;
position: absolute;
left: 0;
transition: all 1s linear;
}
#box div {
width: 500px;
height: 300px;
float: left;
background-color: #7A8FD9;
color: white;
font-size: 50px;
line-height: 300px;
text-align: center;
}
</style>
</head>
<body>
<div id="wrap">
<div id="box">
<div>1</div>
<div>2</div>
<div>3</div>
</div>
</div>
</body>
<script>
//JS版本轮播图
setInterval(
function(){
//让box向左移动每次移动500px
var l = box.offsetLeft;
l -= 500;
if (l < -1000) {
l = 0 ;
}
box.style.left = l + "px";
},2000)
</script>
</html>