/** * * 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 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(){}} 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; var _self = this; var stime,sp=0,isup=0; $(_self).css({overflow:"hidden",position:"relative",padding:"0px"}); var 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(57); 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(); }); 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(); 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(); 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