锘
;(function($){
$.fn.jcImgScroll = function(options) {
var defaults = {
speed : 400,
width : 370,
height : 206,
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);
};
//鍒濆鍖朌OM瀵硅薄
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 +"";
};
};
//鍒濆鍖栬幏鍙朌OM鏁版嵁
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)