//婊氬姩鍥剧墖鏋勯€犲嚱鏁? function scrollpic(scrollcontid,arrleftid,arrrightid,dotlistid,listtype){ this.scrollcontid = scrollcontid; //鍐呭瀹瑰櫒id this.arrleftid = arrleftid; //宸︾澶碔d this.arrrightid = arrrightid; //鍙崇澶碔d this.dotlistid = dotlistid; //鐐瑰垪琛↖d this.listtype = listtype; //鍒楄〃绫诲瀷 this.dotclassname = "dotitem";//鐐筩lassname this.dotonclassname = "dotitemon";//褰撳墠鐐筩lassname this.dotobjarr = []; this.listevent = "onclick"; this.circularly = true; //寰幆婊氬姩锛堟棤缂濆惊鐜級 this.pagewidth = 0; //缈婚〉瀹藉害 this.framewidth = 0; //鏄剧ず妗嗗搴? this.speed = 10; //绉诲姩閫熷害(鍗曚綅姣锛岃秺灏忚秺蹇? this.space = 10; //姣忔绉诲姩鍍忕礌(鍗曚綅px锛岃秺澶ц秺蹇? this.upright = false; //鍨傜洿鐨勬粴鍔? this.pageindex = 0; this.autoplay = false; this.autoplaytime = 5; //绉? this._autotimeobj; this._scrolltimeobj; this._state = "ready"; // ready | floating | stoping this.stripdiv = document.createelement("div"); this.ldiv01 = document.createelement("div"); this.ldiv02 = document.createelement("div"); }; scrollpic.prototype = { version : "1.41", author : "mengjia", pagelength : 0, touch : true, initialize : function(){ //鍒濆鍖? var thistemp = this; if(!this.scrollcontid){ throw new error("蹇呴』鎸囧畾scrollcontid."); return; }; this.scdiv = this.$(this.scrollcontid); if(!this.scdiv){ throw new error("scrollcontid涓嶆槸姝g‘鐨勫璞?(scrollcontid = \""+ this.scrollcontid +"\")"); return; }; //this.scdiv.style[this.upright?'height':'width'] = this.framewidth + "px"; this.scdiv.style.overflow = "hidden"; //html this.ldiv01.innerhtml = this.scdiv.innerhtml; this.scdiv.innerhtml = ""; this.scdiv.appendchild(this.stripdiv); this.stripdiv.appendchild(this.ldiv01); if(this.circularly){//鏃犵紳寰幆 this.stripdiv.appendchild(this.ldiv02); this.ldiv02.innerhtml = this.ldiv01.innerhtml }; this.stripdiv.style.overflow = "hidden"; this.stripdiv.style.zoom = "1"; this.stripdiv.style[this.upright?'height':'width'] = "32766px"; if(!this.upright){ this.ldiv01.style.cssfloat = "left"; this.ldiv01.style.stylefloat = "left"; this.ldiv01.style.overflow = "hidden"; }; this.ldiv01.style.zoom = "1"; if(this.circularly && !this.upright){ //鏃犵紳寰幆璁剧疆css this.ldiv02.style.cssfloat = "left"; this.ldiv02.style.stylefloat = "left"; this.ldiv02.style.overflow = "hidden"; }; this.ldiv02.style.zoom = "1"; this.addevent(this.scdiv,"mouseover",function(){thistemp.stop()}); this.addevent(this.scdiv,"mouseout",function(){thistemp.play()}); //arrowhead event //left if(this.arrleftid){ this.alobj = this.$(this.arrleftid); if(this.alobj){ this.addevent(this.alobj,"mousedown",function(){thistemp.rightmousedown()}); this.addevent(this.alobj,"mouseup",function(){thistemp.rightend()}); this.addevent(this.alobj,"mouseout",function(){thistemp.rightend()}); }; }; //right if(this.arrrightid){ this.arobj = this.$(this.arrrightid); if(this.arobj){ this.addevent(this.arobj,"mousedown",function(){thistemp.leftmousedown()}); this.addevent(this.arobj,"mouseup",function(){thistemp.leftend()}); this.addevent(this.arobj,"mouseout",function(){thistemp.leftend()}); }; }; var pages = math.ceil(this.ldiv01[this.upright?'offsetheight':'offsetwidth'] / this.framewidth),i,tempobj; this.pagelength = pages; //dot if(this.dotlistid){ this.dotlistobj = this.$(this.dotlistid); this.dotlistobj.innerhtml = ""; if(this.dotlistobj){ for(i=0;i= this.ldiv01[this._swidth]){ this.scdiv[this._scroll] = this.scdiv[this._scroll] + this.space - this.ldiv01[this._swidth]; }else{ this.scdiv[this._scroll] += this.space; }; }else{ if(this.scdiv[this._scroll] + this.space >= this.ldiv01[this._swidth] - this.framewidth){ this.scdiv[this._scroll] = this.ldiv01[this._swidth] - this.framewidth; //鍋? this.leftend(); }else{ this.scdiv[this._scroll] += this.space; }; }; this.accountpageindex(); }, moveright : function(){ if(this.circularly){ //鏃犵紳寰幆 if(this.scdiv[this._scroll] - this.space <= 0){ this.scdiv[this._scroll] = this.ldiv01[this._swidth] + this.scdiv[this._scroll] - this.space; }else{ this.scdiv[this._scroll] -= this.space; }; }else{ if(this.scdiv[this._scroll] - this.space <= 0){ this.scdiv[this._scroll] = 0; //鍋? this.rightend(); }else{ this.scdiv[this._scroll] -= this.space; }; }; this.accountpageindex(); }, leftend : function(){ if(this._state != "floating" && this._state != 'touch'){return}; this._state = "stoping"; clearinterval(this._scrolltimeobj); var fill = this.pagewidth - this.scdiv[this._scroll] % this.pagewidth; this.move(fill); }, rightend : function(){ if(this._state != "floating" && this._state != 'touch'){return}; this._state = "stoping"; clearinterval(this._scrolltimeobj); var fill = - this.scdiv[this._scroll] % this.pagewidth; this.move(fill); }, move : function(num,quick){ var thistemp = this; var thismove = num/5; var theend = false; if(!quick){ if(thismove > this.space){thismove = this.space}; if(thismove < -this.space){thismove = -this.space}; }; if(math.abs(thismove)<1 && thismove!=0){ thismove = thismove>=0?1:-1; }else{ thismove = math.round(thismove); }; var temp = this.scdiv[this._scroll] + thismove; if(thismove>0){ if(this.circularly){ //鏃犵紳寰幆 if(this.scdiv[this._scroll] + thismove >= this.ldiv01[this._swidth]){ this.scdiv[this._scroll] = this.scdiv[this._scroll] + thismove - this.ldiv01[this._swidth]; }else{ this.scdiv[this._scroll] += thismove; }; }else{ if(this.scdiv[this._scroll] + thismove >= this.ldiv01[this._swidth] - this.framewidth){ this.scdiv[this._scroll] = this.ldiv01[this._swidth] - this.framewidth; this._state = "ready"; theend = true; //return; }else{ this.scdiv[this._scroll] += thismove; }; }; }else{ if(this.circularly){ //鏃犵紳寰幆 if(this.scdiv[this._scroll] + thismove < 0){ this.scdiv[this._scroll] = this.ldiv01[this._swidth] + this.scdiv[this._scroll] + thismove; }else{ this.scdiv[this._scroll] += thismove; }; }else{ if(this.scdiv[this._scroll] - thismove < 0){ this.scdiv[this._scroll] = 0; this._state = "ready"; theend = true; //return; }else{ this.scdiv[this._scroll] += thismove; }; }; }; if(typeof(this.onpagechange) === 'function'){ this.onpagechange(); }; if(theend){ return; }; num -= thismove; if(math.abs(num) == 0){ this._state = "ready"; if(this.autoplay){this.play()}; this.accountpageindex(); return; }else{ this.accountpageindex(); this._scrolltimeobj = settimeout(function(){thistemp.move(num,quick)},this.speed) }; }, pre : function(){ if(this._state != "ready"){return}; this._state = "stoping"; this.pageto(this.pageindex - 1); }, next : function(restar){ if(this._state != "ready"){return}; this._state = "stoping"; if(this.circularly){ this.pageto(this.pageindex + 1); }else{ if(this.scdiv[this._scroll] >= this.ldiv01[this._swidth] - this.framewidth){ this._state = "ready"; if(restar){this.pageto(0)}; }else{ this.pageto(this.pageindex + 1); }; }; }, play : function(){ var thistemp = this; if(!this.autoplay){return}; clearinterval(this._autotimeobj); this._autotimeobj = setinterval(function(){thistemp.next(true)},this.autoplaytime * 1000); }, stop : function(){ clearinterval(this._autotimeobj); }, pageto : function(num){ if(this.pageindex == num){return}; if(num < 0){num = this.pagelength - 1}; cleartimeout(this._scrolltimeobj); this._state = "stoping"; var fill = num * this.framewidth - this.scdiv[this._scroll]; this.move(fill,true); }, accountpageindex : function(){ var pageindex = math.floor(this.scdiv[this._scroll] / this.framewidth); if(pageindex == this.pageindex){return}; this.pageindex = pageindex; if(this.pageindex > math.floor(this.ldiv01[this.upright?'offsetheight':'offsetwidth'] / this.framewidth )){this.pageindex = 0}; if(typeof(this.onnowpage) === 'function'){ this.onnowpage(this.pageindex); } var i; //alert(this.pageindex); for(i=0;i 1){ //澶氱偣瑙︽懜 this.ipadstatus = 'ok'; return; }; this.ipadlastx = e.touches[0].pagex; var cx = this.ipadx - this.ipadlastx; if(this.ipadstatus == 'ok'){ if(this.ipadscrolly == window.pageyoffset && this.ipadscrollx == window.pagexoffset && math.abs(cx)>20){ //妯悜瑙︽懜 this.ipadstatus = 'touch'; }else{ return; }; }; this._state = 'touch'; var scrollnum = this.scdivscrollleft + cx; if(scrollnum >= this.ldiv01[this._swidth]){ scrollnum = scrollnum - this.ldiv01[this._swidth]; }; if(scrollnum < 0){ scrollnum = scrollnum + this.ldiv01[this._swidth]; }; this.scdiv[this._scroll] = scrollnum; e.preventdefault(); }, _touchend : function(e){ if(this.ipadstatus != 'touch'){return}; this.ipadstatus = 'ok'; //this._state = 'ready'; var cx = this.ipadx - this.ipadlastx; if(cx<0){ this.rightend(); }else{ this.leftend(); }; this.play(); }, $ : function(objname){if(document.getelementbyid){return eval('document.getelementbyid("'+objname+'")')}else{return eval('document.all.'+objname)}}, isie : navigator.appversion.indexof("msie")!=-1?true:false, //event addevent : function(obj,eventtype,func){if(obj.attachevent){obj.attachevent("on" + eventtype,func);}else{obj.addeventlistener(eventtype,func,false)}}, delevent : function(obj,eventtype,func){ if(obj.detachevent){obj.detachevent("on" + eventtype,func)}else{obj.removeeventlistener(eventtype,func,false)} }, //cookie readcookie : function(l){var i="",i=l+"=";if(document.cookie.length>0){var offset=document.cookie.indexof(i);if(offset!=-1){offset+=i.length;var end=document.cookie.indexof(";",offset);if(end==-1)end=document.cookie.length;i=unescape(document.cookie.substring(offset,end))}};return i}, writecookie : function(o,o,l,i){var i="",c="";if(l!=null){i=new date((new date).gettime()+l*3600000);i="; expires="+i.togmtstring()};if(i!=null){c=";domain="+i};document.cookie=o+"="+escape(o)+i+c}, //style readstyle:function(i,i){if(i.style[i]){return i.style[i]}else if(i.currentstyle){return i.currentstyle[i]}else if(document.defaultview&&document.defaultview.getcomputedstyle){var l=document.defaultview.getcomputedstyle(i,null);return l.getpropertyvalue(i)}else{return null}} };