/*
* jquery - jcimgscroll v1.4
* copyright(c) 2012 by adam’
* date: 2012-08-30
* qq : 1741498
*/
;(function($){
$.fn.jcimgscroll = function(options) {
var defaults = {
speed : 400,
width : 618,
height : 342,
offsetx : 100,
setzoom : .7,
loadclass : "loading",
position:"center",
count :5,
arrow : {
width:110,
height:342,
x:20,
y:0
},
numbtn : false,
setnumbtn : {
width : 19,
height : 18,
x : 0,
y : 362
},
title:true,
settitle : {
height:35,
border:8,
bgcolor:"#6ba600",
color:"#fff",
padding:20,
opacity:.8
}
};
var options = $.extend(defaults,options);
return this.each(function() {
var _self = $(this),
_arrdata = [],
_idx = 0,
_center = 0,
$imglist = $("a",_self),
$imgwrap = $("ul",_self),
$imgwraplist = $("li",$imgwrap),
fngetindexarr = function(index,len){ // 当前索引,长度
var arrcurridx = [index];
for(b=0;b<=len;b++){
arrcurridx.push(index+(b+1));
arrcurridx.unshift(index-(b+1)<0?99:index-(b+1));
};
return arrcurridx;
},
setsize = function(dom,l,t,w,h,z,s){
dom.show()
.css("z-index",z)
.animate({"top":t,"left":l,"height":h,"width":w},s);
};
//初始化dom对象
object = function(length){
this.length = length;
this.setnum = options.setnumbtn;
this.numbtndom = function(list,w,h,l,t){
return "
"+ list +"";
};
this.arrow = function(l,r,w,h,x,y){
return "";
};
this.hoverdom = function(t,w,h,b,bg,p,c,lh){
return ""+ t +"";
};
};
//初始化获取dom数据
object.prototype.initial = function(callback){
if(options.count > this.length) { //this.length
alert("\"count\" parameter can not be greater than the total number of pictures, you must base !");
return false;
} else if(options.count < 0) {
alert("\"count\" parameter can not be negative, you must base !");
return false;
} else if(options.count%2 === 0) {
alert("\"count\" parameter must base !");
return false;
};
this.arrnumlist = [];
this.arrimgobj = [];
this.arrdata = [];
this.centeridx = math.round(this.length/2)-1;
this.centercount = math.floor(options.count/2)-1,
_idx = this.centeridx;
_center = this.centercount;
this.indexarr = fngetindexarr(this.centeridx,this.centercount); //获取当前索引组
//console.log(this.indexarr)
$imgwrap.css({"position":"relative","width":options.width,"height":options.height,"margin":"0 auto"});
var a=null,b=null,c=null,stmpdd=null,t=2,t2=this.centercount+1,
cenidxarr = this.indexarr[this.centercount+1],
wrapl = $imgwrap.offset().left,
wrapr = $imgwrap.offset().left+options.width,
setpos = function(mode,height){
var npos = null;
switch(mode){
case "top" :
npos = 0;
break;
case "center" :
npos = (options.height - height)*0.5;
break;
case "bottom" :
npos = options.height - height;
break;
default :
alert("parameters \"position\" error, \"top\", \"center\", \"bottom\" !")
};
return npos;
};
for(a=0;acenidxarr?a-t:a,
tmp = a>cenidxarr?a-this.centeridx:t2, //核心索引
width = math.round(options.width/tmp*options.setzoom),
height = math.round(options.height/tmp*options.setzoom),
top = math.round(setpos(options.position,height))
left = math.round(options.offsetx*tmp);
//console.log(tmp)
if(acenidxarr){
t+=2;
left = (options.width-width)+left;
};
if(a==cenidxarr){
othis.addclass("select");
width = options.width;
height = options.height;
left = 0;
top = 0;
};
setsize(othis,left,top,width,height,zindex,options.speed*1.5);
this.arrdata.push([left,top,width,height,zindex]);
break;
};
};
//输出标题dom
if(options.title){
othis.prepend(this.hoverdom(stitle,
options.width,
options.height,
options.settitle.border,
options.settitle.bgcolor,
options.settitle.padding,
options.settitle.color,
options.settitle.height
))
.find("div")
.css("opacity",0)
.end()
.find("b")
.css("opacity",0);
};
//获取数字按钮
if(options.numbtn){
var numstyle = "cursor:pointer;float:left;height:"+this.setnum.height+"px;width:"+this.setnum.width+"px;overflow:hidden;";
if(this.centeridx === a){
stmpdd = "- "+ a +"
";
} else {
stmpdd = "- "+ a +"
";
};
this.arrnumlist.push(stmpdd);
};
};
//输出箭头按钮
_self.prepend(this.arrow(wrapl,wrapr,options.arrow.width,options.arrow.height,options.arrow.x,options.arrow.y))
.find("em")
.show(0);
//输出数字按钮
if(this.arrnumlist.length !=0 ){
var numlistdom = this.arrnumlist.join(""),
numwrapwidth = this.setnum.width*this.length,
numwrapheight = this.setnum.height,
numwrapleft = (_self.width()-numwrapwidth)*0.5 + this.setnum.x;
_self.append(this.numbtndom(numlistdom,numwrapwidth,numwrapheight,numwrapleft,this.setnum.y))
.find("dl")
.show();
};
callback.call(this,this.arrimgobj);
return this.arrdata;
};
//调用对象 、操作
var o = new object($imglist.length);
_arrdata = o.initial(function(arrimg){
for(var b in arrimg){
arrimg[b].tmp = b;
arrimg[b].onload = function(){
var idx = this.tmp,
$thisimg = $imglist.eq(idx);
$thisimg.html($(arrimg[idx]))
.find("img")
.fadein(600)
.parents("li")
.removeclass(options.loadclass);
};
};
//释放对象
(function(obj){
var d=null,arg = arguments,len=arg.length;
for(d=1;d 0) {
_idx = _idx -1;
imgscroll(_idx,_arrdata,$dd);
};
return false;
});
$next.click(function(){
if(_idx < imglength-1) {
_idx = _idx + 1;
imgscroll(_idx,_arrdata,$dd);
};
return false;
});
$dd.click(function(){
_idx = $(this).index();
imgscroll(_idx,_arrdata,$dd);
});
if(options.title){
var borderwidth = options.settitle.border,
warpheight = options.height,
warpwidth = options.width,
textheight = options.settitle.height;
$("li.select",_self).live("mouseover",function(){
$(this).find("div").show().animate({"opacity":options.settitle.opacity },100);
$(this).find("b").show().delay(100).stop().animate({"height":textheight,"opacity":options.settitle.opacity},150);
return false;
})
$imgwraplist.mouseleave(function(){
$(this).find("b").show().stop().animate({"height":0,"opacity":0},150);
$(this).find("div").delay(150).stop().animate({"opacity":0 },100);
return false;
});
};
return false;
});
};
})(jquery)