怎么用html5+css3 实现图片轮播

如题所述

1、首先我们创建一个简单的项目,如图所示包括html,css和img三个。

2、这里是html文件,引入css和html代码文件,如图所示。

3、这里是css文件代码,上面是div和图片显示的效果代码,后面是动画效果。

4、这里是事件,这里定义了四个时间段的状态,兼容了ie的。

5、如图所示这里是效果图,会根据时间轮播显示下一张图片 了。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-06-27
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="jquery-3.2.1.js"></script>
<title>轮播特效</title>
<style>
.box1{
width:200px;
height:300px;
border:1px dotted black;
background: #aaa;
overflow: hidden;
}
.item{
width: 198px;
height:200px;
border:1px solid red;
float:left;
background:#ff00cc;
}
.cont{
width:1000px;
position:relative;
}
</style>
</head>
<body>
<div class="box1">
<div class="cont">
<div class="item" index="0">0000</div>
<div class="item" index="1">1111</div>
<div class="item" index="2">2222</div>
<div class="item" index="3">3333</div>
<div class="item" index="4">4444</div>
</div>
</div>
</body>
<script type="text/javascript">
var index=0;
$(".box1").on("click",function(){
var curr=(index++)%5;
console.log(1111);
$(".cont").animate({left:"-200px"},1000,function(){
$(".cont").css("left",0);
$(".item[index="+ curr +"]").appendTo($(".cont"));
});
});
</script>
</html>本回答被网友采纳
相似回答