forked from rochal/jQuery-slimScroll
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slimScroll.min.js
8 lines (8 loc) · 3.71 KB
/
slimScroll.min.js
1
2
3
4
5
6
7
8
/*! Copyright (c) 2011 Piotr Rochala (http://rocha.la)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* Version: 0.5.0
*
*/
var priorityScrollingActive=false;(function(a){jQuery.fn.extend({slimScroll:function(b){var c={wheelStep:20,width:"auto",height:"250px",size:"7px",color:"#000",position:"right",distance:"1px",start:"top",opacity:.4,alwaysVisible:false,railVisible:false,railColor:"#333",railOpacity:"0.2",railClass:"slimScrollRail",barClass:"slimScrollBar",wrapperClass:"slimScrollDiv",allowPageScroll:false,scroll:0};var d=ops=a.extend(c,b);this.each(function(){function I(a,b,c){var d=a;if(b){d=parseInt(F.css("top"))+a*l/100*F.outerHeight();var e=B.outerHeight()-F.outerHeight();d=Math.min(Math.max(d,0),e);F.css({top:d+"px"})}h=parseInt(F.css("top"))/(B.outerHeight()-F.outerHeight());d=h*(B[0].scrollHeight-B.outerHeight());if(c){d=a;var f=d/B[0].scrollHeight*B.outerHeight();F.css({top:f+"px"})}B.scrollTop(d);L();M()}function K(){g=Math.max(B.outerHeight()/B[0].scrollHeight*B.outerHeight(),j);F.css({height:g+"px"})}function L(){K();clearTimeout(f);if("slimScrollPriority"==B.attr("class")){priorityScrollingActive=true}k=z&&h==~~h;if(g>=B.outerHeight()){k=true;return}F.stop(true,true).fadeIn("fast");if(w){E.stop(true,true).fadeIn("fast")}}function M(){if(!v){f=setTimeout(function(){if(!c&&!e){F.fadeOut("slow");E.fadeOut("slow");if("slimScrollPriority"==B.attr("class")){priorityScrollingActive=false}}},1e3)}}var b,c,e,f,g,h,i="<div></div>",j=30,k=false,l=parseInt(d.wheelStep),m=d.width,n=d.height,p=d.size,q=d.color,r=d.position,s=d.distance,t=d.start,u=d.opacity,v=d.alwaysVisible,w=d.railVisible,x=d.railColor,y=d.railOpacity,z=d.allowPageScroll,A=d.scroll;var B=a(this);if(B.parent().hasClass(d.wrapperClass)){if(A){F=B.parent().find("."+d.barClas);E=B.parent().find("."+d.railClass);I(B.scrollTop()+parseInt(A),false,true)}return}var C=a(i).addClass(d.wrapperClass).css({overflow:"hidden",width:m});var D=parseInt(B.css("top"),10);if(0<D){C.css({position:"absolute",top:B.css("top"),bottom:B.css("bottom")})}else{C.css({position:"relative",height:n})}B.css({overflow:"hidden",width:m,height:n,top:"0px"});var E=a(i).addClass(d.railClass).css({width:p,height:"100%",position:"absolute",top:0,display:v&&w?"block":"none","border-radius":p,background:x,opacity:y,zIndex:90});var F=a(i).addClass(d.barClass).css({background:q,width:p,position:"absolute",top:0,opacity:u,display:v?"block":"none","border-radius":p,BorderRadius:p,MozBorderRadius:p,WebkitBorderRadius:p,zIndex:99});var G=r=="right"?{right:s}:{left:s};E.css(G);F.css(G);B.wrap(C);B.parent().append(F);B.parent().append(E);F.draggable({axis:"y",containment:"parent",start:function(){e=true},stop:function(){e=false;M()},drag:function(b){I(0,a(this).position().top,false)}});E.hover(function(){L()},function(){M()});F.hover(function(){c=true},function(){c=false});B.hover(function(){if("slimScrollPriority"==B.attr("class")){priorityScrollingActive=true}b=true;L();M()},function(){b=false;M()});var H=function(a){if(!b){return}if(priorityScrollingActive&&"slimScrollPriority"!=B.attr("class")){return}var a=a||window.event;var c=0;if(a.wheelDelta){c=-a.wheelDelta/120}if(a.detail){c=a.detail/3}I(c,true);if(a.preventDefault&&!k){a.preventDefault()}if(!k){a.returnValue=false}};var J=function(){if(window.addEventListener){this.addEventListener("DOMMouseScroll",H,false);this.addEventListener("mousewheel",H,false)}else{document.attachEvent("onmousewheel",H)}};J();K();if(t=="bottom"){F.css({top:B.outerHeight()-F.outerHeight()});I(0,true)}else if(typeof t=="object"){I(a(t).position().top,null,true);if(!v){F.hide()}}});return this}});jQuery.fn.extend({slimscroll:jQuery.fn.slimScroll})})(jQuery)