(function($) {
$.fn.poposlides = function(options) {
var settings = $.extend({
auto:true, //自动播放
nav:true, //切换按钮
playspeed:5000, //自动播放速度
fadespeed:500, //淡入淡出速度
loop:true, //循环播放
pagination:true, //页码显示
pagecenter:true, //页码居中
prev:".prev", //上一页按钮
next:".next" //下一页按钮
}, options);
return this.each(function() {
var $this = $(this),
slide = $this.children(),
index = 0;
len = slide.length-1,
slidewidth = $this.width(),
prev = settings.prev,
next = settings.next;
//初始隐藏其它页,显示当前页
if(!navigator.useragent.match(/mobile/i)){
slide.hide();
slide.eq(index).show();
}else{
slide.css({
"opacity":"0"
});
slide.eq(index).css({
"opacity":"1"
});
};
//显示当前页
slidefadein = function(){
if(!navigator.useragent.match(/mobile/i)){
slide.fadeout(settings.fadespeed);
slide.eq(index).fadein(settings.fadespeed);
}else{
slide.css({
"opacity":"0",
"-webkit-transition": settings.fadespeed/1000+"s"
});
slide.eq(index).css({
"opacity":"1",
"-webkit-transition": settings.fadespeed/1000+"s"
});
};
};
//翻页加,判断是否循环
slideadd = function() {
if(settings.loop){
index == len?index=0:index++;
}else{
index == len?index=len:index++;
};
slidefadein();
};
//翻页减,判断是否循环
slideminus = function() {
if(settings.loop){
index == 0?index=len:index--;
}else{
index == 0?index=0:index--;
};
slidefadein();
};
//页码
pagnation = function(){
var $paginationbox = $("");
var paginationstr ="";
for(var i=1;i<=len+1;i++){
}
$paginationbox.append(paginationstr);
$this.after($paginationbox);
$(".pagination li a").eq(index).addclass("active");
};
//当前页码
pageactive = function(){
$(".pagination li a").removeattr("class")
$(".pagination li a").eq(index).addclass("active");
}
//是否需要左右导航图标
if(settings.nav) {
var navstr = "" +
"";
$this.after(navstr);
$(next).click(function(){
slideadd();
});
$(prev).click(function(){
slideminus();
})
};
//是否需要页码
if(settings.pagination) {
pagnation();
$(prev).click(function(){ pageactive();});
$(next).click(function(){ pageactive();});
$(".pagination li").click(function(){
var idx = $(this).index()-1;
index = idx;
slideadd();
pageactive();
});
};
//页码居中
if(settings.pagecenter){
var pw = $(".pagination").width();
$(".pagination").css({
"position":"absolute",
"left":"50%",
"bottom":"5px",
"margin-left":-pw/2,
"z-index": "99"
})
};
//是否自动播放
if(settings.auto){
var play = setinterval(function(){
slideadd();
pageactive();
},settings.playspeed);
$this.nextall().hover(function () {
clearinterval(play);
},
function(){
play = setinterval(function(){
slideadd();
pageactive();
},settings.playspeed);
});
};
});
};
})(jquery);