1、单个非无缝滚动轮播
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>27-1无限轮播</title>
<style>
ul,li{
list-style: none;
}
*{
margin: 0;
padding: 0;
}
.ct-img>li{
float: left;
width: 310px;
height: 210px;
display: none;
}
li img{
width: 310px;
height: 210px;
}
.clearfix:after{
content: "";
display: block;
clear: both;
}
.ct-bottom>li{
border-bottom: 5px solid #555;
float: left;
cursor: pointer;
width: 20px;
margin: 0 5px;
border-radius: 2px;
}
.ct-bottom{
position: absolute;
top: 180px;
left: 95px;
}
body{
position: relative;
}
a.change{
text-decoration: none;
font-size: larger;
font-weight: 900;
background-color: #666;
color: #fff;
display: inline-block;
vertical-align: middle;
padding: 15px;
width: 10px;
height: 10px;
line-height: 10px;
border-radius: 25px;
opacity: 0.7;
}
a.pre{
position: absolute;
left: 10px;
top: 80px;
}
a.next{
position: absolute;
left: 250px;
top: 80px;
}
a.change:hover{
background-color: #444;
}
</style>
</head>
<body>
<div class="ct">
<ul class="clearfix ct-img">
<li data-nub="0"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-fa29da09e1abe792.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="1"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-0ed4f2fd9ea0b571.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="2"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-e181309822223f13.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="3"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-beeaa45457e1cc51.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
</ul>
<ul class="ct-bottom clearfix">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<a href="####" class="pre change"> < </a>
<a href="####" class="next change"> > </a>
</div>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
var clock=false;
show(0);
setInterval(function () {
playNext()
},2000);
function show(num) {
if (clock){return;}
clock=true;
$(".ct-img").children().eq(num).siblings().css("display","none");
$(".ct-bottom").children().eq(num).css("border-bottom-color","white");
$(".ct-bottom").children().eq(num).siblings().css("border-bottom-color","#555");
$(".ct-img").children().eq(num).fadeOut(500);
$(".ct-img").children().eq(num).fadeIn(500,function () {
clock=false
});
cur=num;
return cur;
}
function playNext() {
var nextNum=cur+1;
if (nextNum===4){
show(0)
}
else show(nextNum)
}
$(".next").on("click",function () {
playNext();
});
$(".pre").on("click",function () {
playPre();
});
function playPre() {
var preNum=cur-1;
if (preNum===-1){
show(3)
}
else show(preNum)
}
$(".ct-bottom>li").on("click",function () {
var $cur=$(this),
indexNum=$cur.index();
show(indexNum);
})
</script>
</body>
</html>
2、多个个非无缝滚动轮播
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>27-1无限轮播</title>
<style>
ul,li{
list-style: none;
}
*{
margin: 0;
padding: 0;
}
.ct-img>li{
float: left;
width: 310px;
height: 210px;
display: none;
}
li img{
width: 310px;
height: 210px;
}
.clearfix:after{
content: "";
display: block;
clear: both;
}
.ct-bottom>li{
border-bottom: 5px solid #555;
float: left;
cursor: pointer;
width: 20px;
margin: 0 5px;
border-radius: 2px;
}
.ct-bottom{
position: absolute;
top: 180px;
left: 95px;
}
.ct{
position: relative;
}
a.change{
text-decoration: none;
font-size: larger;
font-weight: 900;
background-color: #666;
color: #fff;
display: inline-block;
vertical-align: middle;
padding: 15px;
width: 10px;
height: 10px;
line-height: 10px;
border-radius: 25px;
opacity: 0.7;
}
a.pre{
position: absolute;
left: 10px;
top: 80px;
}
a.next{
position: absolute;
left: 250px;
top: 80px;
}
a.change:hover{
background-color: #444;
}
</style>
</head>
<body>
<div id="wrap">
<div class="ct">
<ul class="clearfix ct-img">
<li data-nub="0"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-fa29da09e1abe792.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="1"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-0ed4f2fd9ea0b571.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="2"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-e181309822223f13.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="3"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-beeaa45457e1cc51.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
</ul>
<ul class="ct-bottom clearfix">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<a href="####" class="pre change"> < </a>
<a href="####" class="next change"> > </a>
</div>
<div class="ct">
<ul class="clearfix ct-img">
<li data-nub="0"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-e181309822223f13.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="1"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-0ed4f2fd9ea0b571.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="2"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-fa29da09e1abe792.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="3"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-beeaa45457e1cc51.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
</ul>
<ul class="ct-bottom clearfix">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<a href="####" class="pre change"> < </a>
<a href="####" class="next change"> > </a>
</div>
<div class="ct">
<ul class="clearfix ct-img">
<li data-nub="0"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-fa29da09e1abe792.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="1"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-0ed4f2fd9ea0b571.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="2"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-e181309822223f13.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="3"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-beeaa45457e1cc51.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
</ul>
<ul class="ct-bottom clearfix">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<a href="####" class="pre change"> < </a>
<a href="####" class="next change"> > </a>
</div>
</div>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
/* 自定义jQuery方法(开发jQuery插件常用此方法) 其实 $.fn === $.prototype */
$.fn.allGo = function() {
var $me=$(this),
$ctImg=$me.find(".ct-img"),
$ctBottom=$me.find(".ct-bottom"),
$next=$me.find(".next"),
$pre=$me.find(".pre"),
$ctBottomLi=$me.find(".ct-bottom>li"),
clock=false,
cur=0;
show(0);
setInterval(function () {
playNext()
}, 2000);
function show(num) {
if (clock) {
return;
}
clock = true;
$ctBottom.children().eq(num).css("border-bottom-color", "white");
$ctBottom.children().eq(num).siblings().css("border-bottom-color", "#555");
$ctImg.children().eq(num).siblings().css("display", "none");
$ctImg.children().eq(num).fadeOut(500);
$ctImg.children().eq(num).fadeIn(500, function () {
clock = false
});
cur = num;
return cur;
}
function playNext() {
var nextNum = cur + 1;
if (nextNum === 4) {
show(0)
}
else show(nextNum)
}
$next.on("click", function () {
playNext();
});
$pre.on("click", function () {
playPre();
});
function playPre() {
var preNum = cur - 1;
if (preNum === -1) {
show(3)
}
else show(preNum)
}
$ctBottomLi.on("click", function () {
var $cur = $(this),
indexNum = $cur.index();
show(indexNum);
});
};
$(".ct").each(function () {
$(this).allGo();
});
</script>
</body>
</html>
3、无缝轮播
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>27-1无限轮播</title>
<style>
ul,li{
list-style: none;
}
*{
margin: 0;
padding: 0;
}
.ct-img>li{
float: left;
width: 310px;
height: 210px;
}
.ct-img{
position: absolute;
}
img{
width: 310px;
height: 210px;
}
.clearfix:after{
content: "";
display: block;
clear: both;
}
.ct-bottom>li{
border-bottom: 5px solid #555;
float: left;
cursor: pointer;
width: 20px;
margin: 0 5px;
border-radius: 2px;
}
.ct-bottom{
position: absolute;
top: 180px;
left: 95px;
}
.ct{
position: relative;
height: 210px;
width: 310px;
overflow: hidden;
}
a.change{
text-decoration: none;
font-size: larger;
font-weight: 900;
background-color: #666;
color: #fff;
display: inline-block;
vertical-align: middle;
padding: 15px;
width: 10px;
height: 10px;
line-height: 10px;
border-radius: 25px;
opacity: 0.7;
}
a.pre{
position: absolute;
left: 10px;
top: 80px;
}
a.next{
position: absolute;
left: 250px;
top: 80px;
}
a.change:hover{
background-color: #444;
}
</style>
</head>
<body>
<div class="ct">
<ul class="clearfix ct-img">
<li data-nub="0"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-6ab5d1205bf5e648.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="1"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-4a650bbc5c4aa561.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="2"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-3f5ed4941a5622a1.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
<li data-nub="3"><a href="#">![](http://upload-images.jianshu.io/upload_images/2166980-5e9ce2909a791c90.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)</a></li>
</ul>
<ul class="ct-bottom clearfix">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<a href="####" class="pre change"> < </a>
<a href="####" class="next change"> > </a>
</div>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
var imgWidth=$(".ct-img").children().width(),
clock=false,
nextClock=false,
$liImg=$(".ct-img").children(),
imgCount=$liImg.size();
$(".ct-img").append($liImg.first().clone());
$(".ct-img").prepend($liImg.last().clone());
imgTrueCount=$(".ct-img").children().length;
$(".ct-img").css({"left":0-imgWidth,"width":imgTrueCount*imgWidth});
function showMe(num) {
if (clock){return}
clock=true;
if (-1<num<imgCount){
$(".ct-bottom").children().eq(num).css("border-bottom-color","white");
$(".ct-bottom").children().eq(num).siblings().css("border-bottom-color","#555");
$(".ct-img").animate({left:"-"+imgWidth*(num+1)});
}
if (num===imgCount){
$(".ct-img").animate({"left":"-"+imgWidth*(imgCount+1)},function () {
$(".ct-img").css("left",0-imgWidth);
});
$(".ct-bottom").children().eq(0).css("border-bottom-color","white");
$(".ct-bottom").children().eq(0).siblings().css("border-bottom-color","#555");
}
if (num===-1){
$(".ct-img").animate({"left":"0"},function () {
$(".ct-img").css("left",0-imgWidth*imgCount);
});
$(".ct-bottom").children().eq(imgCount-1).css("border-bottom-color","white");
$(".ct-bottom").children().eq(imgCount-1).siblings().css("border-bottom-color","#555");
}
myIndex=num;
clock=false;
nextClock=false;
return myIndex;
}
function playNext() {
if (myIndex===imgCount){
myIndex=0;
showMe(myIndex+1);
return ;
}
showMe(myIndex+1);
}
function playPre() {
if (myIndex===-1){
myIndex=imgCount-2;
showMe(myIndex);
return ;
}
showMe(myIndex-1)
}
$(".next").on("click",function () {
clearTimeout(timing);
playNext();
circulate();
});
$(".pre").on("click",function () {
clearTimeout(timing);
playPre();
circulate();
});
showMe(0);
circulate();
function circulate() {
timing=setTimeout(function () {
playNext();
circulate();
},3000);
}
$(".ct-bottom").children().on("click", function () {
clearTimeout(timing);
var $cur = $(this),
indexNum = $cur.index();
if (indexNum===0){
showMe(imgCount);
}
else showMe(indexNum);
circulate();
});
</script>
</body>
</html>
4、全屏无缝轮播
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>27-4无限轮播</title>
<style>
ul,li{
list-style: none;
}
*{
margin: 0;
padding: 0;
}
body,html,.wrap,.ct-bg{
width: 100%;
height: 100%;
}
.wrap{
position: relative;
overflow: hidden;
}
.ct-bg{
position: absolute;
}
.ct-bg>li{
float: left;
height: 100%;
width: 100%;
text-align: center;
position: relative;
}
.bg{
background-image:url("http://cdn.jirengu.com/book.jirengu.com/img/6.jpg");
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
height: 100%;
width: 100%;
position: absolute;
}
.clearfix:after{
content: "";
display: block;
clear: both;
}
.ct-bg .ct-text{
position: absolute;
top:50%;
left: 50%;
transform: translate(-50%, -50%);
}
.ct-text>h1{
padding-bottom: 20px;
}
.ct-bottom{
position: absolute;
bottom: 10px;
left: 50%;
transform: translateX(-50%);
}
.ct-bottom>li{
border-bottom: 5px solid #555;
float: left;
cursor: pointer;
width: 20px;
margin: 0 5px;
border-radius: 2px;
}
a.change{
text-decoration: none;
font-size: larger;
font-weight: 900;
background-color: #666;
color: #fff;
display: inline-block;
vertical-align: middle;
padding: 15px;
width: 10px;
height: 10px;
line-height: 10px;
border-radius: 25px;
opacity: 0.7;
position: absolute;
top: 50%;
transform: translateY(-50%);
}
a.pre{
left: 50px;
}
a.next{
right: 50px;
}
a.change:hover{
background-color: #444;
}
</style>
</head>
<body>
<div class="wrap">
<ul class="clearfix ct-bg">
<li>
<div class="bg" data-bg="http://cdn.jirengu.com/book.jirengu.com/img/6.jpg"></div>
<div class="ct-text">
<h1>我是第一张</h1>
<h3>我是标题</h3>
</div>
</li>
<li>
<div class="bg" data-bg="http://cdn.jirengu.com/book.jirengu.com/img/7.jpg"></div>
<div class="ct-text">
<h1>我是第二张</h1>
<h3>我是标题</h3>
</div>
</li>
<li>
<div class="bg" data-bg="http://cdn.jirengu.com/book.jirengu.com/img/8.jpg"></div>
<div class="ct-text">
<h1>我是第三张</h1>
<h3>我是标题</h3>
</div>
</li>
<li>
<div class="bg" data-bg="http://cdn.jirengu.com/book.jirengu.com/img/9.jpg"></div>
<div class="ct-text">
<h1>我是第四张</h1>
<h3>我是标题</h3>
</div>
</li>
</ul>
<ul class="ct-bottom clearfix">
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<a href="####" class="pre change"> < </a>
<a href="####" class="next change"> > </a>
</div>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
var bgLiWidth=$(".ct-bg").children().width(),
clock=false,
nextClock=false,
$bgLi=$(".ct-bg").children(),
bgCount=$bgLi.size();
$(".ct-bg").append($bgLi.first().clone());
$(".ct-bg").prepend($bgLi.last().clone());
bgTrueCount=$(".ct-bg").children().length;
$(".ct-bg").css({"left":0-bgLiWidth,"width":bgTrueCount*bgLiWidth});
$(".ct-bg").children().width(bgLiWidth);
function showMe(num) {
if (clock){return}
clock=true;
if (-1<num<bgCount){
$(".ct-bottom").children().eq(num).css("border-bottom-color","white");
$(".ct-bottom").children().eq(num).siblings().css("border-bottom-color","#555");
$(".ct-bg").animate({left:"-"+bgLiWidth*(num+1)});
isSetBgUrl();
function isSetBgUrl() {
if ($(".bg").eq(num+1).data("setBgUrl")) {return;}
else {trueBgUrl=$(".ct-bg .bg").eq(num+1).attr("data-bg");
$(".bg").eq(num+1).css("background-image",'url('+trueBgUrl+')');
$(".bg").eq(num+1).data("setBgUrl",true) ;
}
}
}
if (num===bgCount){
$(".ct-bg").animate({"left":"-"+bgLiWidth*(bgCount+1)},function () {
$(".ct-bg").css("left",0-bgLiWidth);
});
$(".ct-bottom").children().eq(0).css("border-bottom-color","white");
$(".ct-bottom").children().eq(0).siblings().css("border-bottom-color","#555");
}
if (num===-1){
$(".ct-bg").animate({"left":"0"},function () {
$(".ct-bg").css("left",0-bgLiWidth*bgCount);
});
$(".ct-bottom").children().eq(bgCount-1).css("border-bottom-color","white");
$(".ct-bottom").children().eq(bgCount-1).siblings().css("border-bottom-color","#555");
}
myIndex=num;
clock=false;
nextClock=false;
return myIndex;
}
function playNext() {
if (myIndex===bgCount){
myIndex=0;
showMe(myIndex+1);
return ;
}
showMe(myIndex+1);
}
function playPre() {
if (myIndex===-1){
myIndex=bgCount-2;
showMe(myIndex);
return ;
}
showMe(myIndex-1)
}
$(".next").on("click",function () {
clearTimeout(timing);
playNext();
circulate();
});
$(".pre").on("click",function () {
clearTimeout(timing);
playPre();
circulate();
});
showMe(0);
circulate();
function circulate() {
timing=setTimeout(function () {
playNext();
circulate();
},3000);
}
$(".ct-bottom").children().on("click", function () {
clearTimeout(timing);
var $cur = $(this),
indexNum = $cur.index();
if (indexNum===0){
showMe(bgCount);
}
else showMe(indexNum);
circulate();
});
</script>
</body>
</html>
**本文版权归本人即简书笔名:该账户已被查封 所有,如需转载请注明出处。谢谢! *