/** * * copyright (c) 2009 may(qq104010230) * http://www.winwill.com * http://www.winwill.com/jquery/jscroll.html * admin@winwill.com */ /*--------------------------------------------------------------------------------------------------*/ $.fn.extend({//��ӹ����¼�//by jun mousewheel:function(func){ return this.each(function(){ var _self = this; _self.d = 0;//�������� if($.browser.msie||$.browser.safari){ _self.onmousewheel=function(){_self.d = event.wheeldelta;event.returnvalue = false;func && func.call(_self);}; }else{ _self.addeventlistener("dommousescroll",function(e){ _self.d = e.detail>0?-1:1; e.preventdefault(); func && func.call(_self); },false); } }); } }); $.fn.extend({ jscroll:function(j){ return this.each(function(){ j = j || {} j.bar = j.bar||{};//2������ j.btn = j.btn||{};//2������ j.bar.bg = j.bar.bg||{};//3������ j.bar.bd = j.bar.bd||{};//3������ j.btn.ubg = j.btn.ubg||{};//3������ j.btn.dbg = j.btn.dbg||{};//3������ var dw , dh; var jun = { w:"15px" ,bgurl:"" ,bg:"#efefef" ,bar:{ pos:"up" ,bd:{out:"#b5b5b5",hover:"#ccc"} ,bg:{out:"#fff",hover:"#fff",focus:"orange"}} ,btn:{ btn:true ,ubg:{out:"#ccc",hover:"#fff",focus:"orange"} ,dbg:{out:"#ccc",hover:"#fff",focus:"orange"}} ,fn:function(){} ,rsize:function(){ var _self = this; dw = $(_self).width(), dh = $(_self).height()-1; } } j.w = j.w||jun.w; j.bgurl = j.bgurl||jun.bgurl; j.bg = j.bg||jun.bg; j.bar.pos = j.bar.pos||jun.bar.pos; j.bar.bd.out = j.bar.bd.out||jun.bar.bd.out; j.bar.bd.hover = j.bar.bd.hover||jun.bar.bd.hover; j.bar.bg.out = j.bar.bg.out||jun.bar.bg.out; j.bar.bg.hover = j.bar.bg.hover||jun.bar.bg.hover; j.bar.bg.focus = j.bar.bg.focus||jun.bar.bg.focus; j.btn.btn = j.btn.btn!=undefined?j.btn.btn:jun.btn.btn; j.btn.ubg.out = j.btn.ubg.out||jun.btn.ubg.out; j.btn.ubg.hover = j.btn.ubg.hover||jun.btn.ubg.hover; j.btn.ubg.focus = j.btn.ubg.focus||jun.btn.ubg.focus; j.btn.dbg.out = j.btn.dbg.out||jun.btn.dbg.out; j.btn.dbg.hover = j.btn.dbg.hover||jun.btn.dbg.hover; j.btn.dbg.focus = j.btn.dbg.focus||jun.btn.dbg.focus; j.fn = j.fn||jun.fn; j.rsize = j.rsize||jun.rsize; var _self = this; var stime,sp=0,isup=0; $(_self).css({overflow:"hidden",position:"relative",padding:"0px"}); dw = $(_self).width(), dh = $(_self).height()-1; var sw = j.w ? parseint(j.w) : 21; var sl = dw - sw var bw = j.btn.btn==true ? sw : 0; if($(_self).children(".jscroll-c").height()==null){//�����լ�� $(_self).wrapinner("
"); $(_self).children(".jscroll-c").prepend(""); $(_self).append(" "); } var jscrollc = $(_self).children(".jscroll-c"); var jscrolle = $(_self).children(".jscroll-e"); var jscrollh = jscrolle.children(".jscroll-h"); var jscrollu = jscrolle.children(".jscroll-u"); var jscrolld = jscrolle.children(".jscroll-d"); if($.browser.msie){document.execcommand("backgroundimagecache", false, true);} jscrollc.css({"padding-right":sw}); jscrolle.css({width:sw,background:j.bg,"background-image":j.bgurl}); jscrollh.css({top:bw,background:j.bar.bg.out,"background-image":j.bgurl,"border-color":j.bar.bd.out,width:sw-2}); jscrollu.css({height:bw,background:j.btn.ubg.out,"background-image":j.bgurl}); jscrolld.css({height:bw,background:j.btn.dbg.out,"background-image":j.bgurl}); jscrollh.hover(function(){if(isup==0)$(this).css({background:j.bar.bg.hover,"background-image":j.bgurl,"border-color":j.bar.bd.hover})},function(){if(isup==0)$(this).css({background:j.bar.bg.out,"background-image":j.bgurl,"border-color":j.bar.bd.out})}) jscrollu.hover(function(){if(isup==0)$(this).css({background:j.btn.ubg.hover,"background-image":j.bgurl})},function(){if(isup==0)$(this).css({background:j.btn.ubg.out,"background-image":j.bgurl})}) jscrolld.hover(function(){if(isup==0)$(this).css({background:j.btn.dbg.hover,"background-image":j.bgurl})},function(){if(isup==0)$(this).css({background:j.btn.dbg.out,"background-image":j.bgurl})}) var sch = jscrollc.height(); //var sh = math.pow(dh,2) / sch ;//math.pow(x,y)x��y�η� var sh = (dh-2*bw)*dh / sch if(sh<10){sh=10} var wh = sh/6//����ʱ���������� // sh = parseint(sh); var curt = 0,allows=false; jscrollh.height(sh); if(sch<=dh){jscrollc.css({padding:0});jscrolle.css({display:"none"})}else{allows=true;} if(j.bar.pos!="up"){ curt=dh-sh-bw; sett(); } jscrollh.bind("mousedown",function(e){ j['fn'] && j['fn'].call(_self); isup=1; jscrollh.css({background:j.bar.bg.focus,"background-image":j.bgurl}) var pagey = e.pagey ,t = parseint($(this).css("top")); $(document).mousemove(function(e2){ curt =t+ e2.pagey - pagey;//pagey����������������λ�ã�screeny��ļ�����������λ�� sett(); }); $(document).mouseup(function(){ isup=0; jscrollh.css({background:j.bar.bg.out,"background-image":j.bgurl,"border-color":j.bar.bd.out}) $(document).unbind('mouseup'); $(document).unbind('mousemove'); }); return false; }); jscrollu.bind("mousedown",function(e){ j['fn'] && j['fn'].call(_self); isup=1; jscrollu.css({background:j.btn.ubg.focus,"background-image":j.bgurl}) _self.timesett("u"); $(document).mouseup(function(){ isup=0; jscrollu.css({background:j.btn.ubg.out,"background-image":j.bgurl}) $(document).unbind('mouseup'); cleartimeout(stime); sp=0; }); return false; }); jscrolld.bind("mousedown",function(e){ j['fn'] && j['fn'].call(_self); isup=1; jscrolld.css({background:j.btn.dbg.focus,"background-image":j.bgurl}) _self.timesett("d"); $(document).mouseup(function(){ isup=0; jscrolld.css({background:j.btn.dbg.out,"background-image":j.bgurl}) $(document).unbind('mouseup'); cleartimeout(stime); sp=0; }); return false; }); _self.timesett = function(d){ var self=this; if(d=="u"){curt-=wh;}else{curt+=wh;} sett(); sp+=2; var t =500 - sp*50; if(t<=0){t=0}; stime = settimeout(function(){self.timesett(d);},t); } jscrolle.bind("mousedown",function(e){ j['fn'] && j['fn'].call(_self); curt = curt + e.pagey - jscrollh.offset().top - sh/2; asett(); return false; }); function asett(){ if(curt