diff --git a/slimScroll.js b/slimScroll.js index 02d2de2..a028466 100644 --- a/slimScroll.js +++ b/slimScroll.js @@ -2,7 +2,7 @@ * 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.4.0 + * Version: 0.4.1 * */ (function($) { @@ -179,7 +179,7 @@ if (isWheel) { // move bar with mouse wheel - delta = bar.position().top + y * wheelStep; + delta = parseInt( bar.css('top') ) + y * wheelStep; // move bar, make sure it doesn't go out delta = Math.max(delta, 0); @@ -191,7 +191,7 @@ } // calculate actual scroll amount - var percentScroll = parseInt(bar.position().top) / (me.outerHeight() - bar.outerHeight()); + var percentScroll = parseInt( bar.css('top') ) / (me.outerHeight() - bar.outerHeight()); delta = percentScroll * (me[0].scrollHeight - me.outerHeight()); if (isJump) diff --git a/slimScroll.min.js b/slimScroll.min.js index f4d0dde..4a86387 100644 --- a/slimScroll.min.js +++ b/slimScroll.min.js @@ -2,11 +2,6 @@ * 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.4.0 + * Version: 0.4.1 * - */(function(d){jQuery.fn.extend({slimScroll:function(l){var a=ops=d.extend({wheelStep:20,width:"auto",height:"250px",size:"7px",color:"#000",position:"right",distance:"1px",start:"top",opacity:0.4,alwaysVisible:!1,railVisible:!1,railColor:"#333",railOpacity:"0.2",railClass:"slimScrollRail",barClass:"slimScrollBar",wrapperClass:"slimScrollDiv"},l);this.each(function(){var m,n,o,u,p,q=!1,l=parseInt(a.wheelStep),g=a.width,v=a.height,f=a.size,z=a.color,A=a.position,w=a.distance,r=a.start,B=a.opacity,j= -a.alwaysVisible,x=a.railVisible,C=a.railColor,D=a.railOpacity,b=d(this),E=d("
").addClass(a.wrapperClass).css({position:"relative",overflow:"hidden",width:g,height:v});b.css({overflow:"hidden",width:g,height:v});var h=d("").addClass(a.railClass).css({width:f,height:"100%",position:"absolute",top:0,display:j&&x?"block":"none","border-radius":f,background:C,opacity:D,zIndex:90}),c=d("").addClass(a.barClass).css({background:z,width:f,position:"absolute",top:0,opacity:B, -display:j?"block":"none","border-radius":f,BorderRadius:f,MozBorderRadius:f,WebkitBorderRadius:f,zIndex:99}),g="right"==A?{right:w}:{left:w};h.css(g);c.css(g);b.wrap(E);b.parent().append(c);b.parent().append(h);c.draggable({axis:"y",containment:"parent",start:function(){o=!0},stop:function(){o=!1;i()},drag:function(){k(0,d(this).position().top,!1)}});h.hover(function(){s()},function(){i()});c.hover(function(){n=!0},function(){n=!1});b.hover(function(){m=!0;s();i()},function(){m=!1;i()});var t=function(a){if(m){var a= -a||window.event,b=0;a.wheelDelta&&(b=-a.wheelDelta/120);a.detail&&(b=a.detail/3);k(b,!0);a.preventDefault&&!q&&a.preventDefault();if(!q)a.returnValue=!1}},k=function(a,d,f){var e=a;d&&(e=c.position().top+a*l,e=Math.max(e,0),d=b.outerHeight()-c.outerHeight(),e=Math.min(e,d),c.css({top:e+"px"}));e=parseInt(c.position().top)/(b.outerHeight()-c.outerHeight())*(b[0].scrollHeight-b.outerHeight());f&&(e=a,a=e/b[0].scrollHeight*b.outerHeight(),c.css({top:a+"px"}));b.scrollTop(e);s();i()};(function(){window.addEventListener? -(this.addEventListener("DOMMouseScroll",t,!1),this.addEventListener("mousewheel",t,!1)):document.attachEvent("onmousewheel",t)})();var y=function(){p=Math.max(b.outerHeight()/b[0].scrollHeight*b.outerHeight(),30);c.css({height:p+"px"})};y();var s=function(){y();clearTimeout(u);p>=b.outerHeight()?q=!0:(c.fadeIn("fast"),x&&h.fadeIn("fast"))},i=function(){j||(u=setTimeout(function(){!n&&!o&&(c.fadeOut("slow"),h.fadeOut("slow"))},1E3))};"bottom"==r?(c.css({top:"auto",bottom:0}),k(0,!0)):"object"==typeof r&& -(k(d(r).position().top,null,!0),j||c.hide())});return this}});jQuery.fn.extend({slimscroll:jQuery.fn.slimScroll})})(jQuery); \ No newline at end of file + */(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:!1,railVisible:!1,railColor:"#333",railOpacity:"0.2",railClass:"slimScrollRail",barClass:"slimScrollBar",wrapperClass:"slimScrollDiv"},d=ops=a.extend(c,b);this.each(function(){var b,c,e,f,g,h="",i=30,j=!1,k=parseInt(d.wheelStep),l=d.width,m=d.height,n=d.size,p=d.color,q=d.position,r=d.distance,s=d.start,t=d.opacity,u=d.alwaysVisible,v=d.railVisible,w=d.railColor,x=d.railOpacity,y=a(this),z=a(h).addClass(d.wrapperClass).css({position:"relative",overflow:"hidden",width:l,height:m});y.css({overflow:"hidden",width:l,height:m});var A=a(h).addClass(d.railClass).css({width:n,height:"100%",position:"absolute",top:0,display:u&&v?"block":"none","border-radius":n,background:w,opacity:x,zIndex:90}),B=a(h).addClass(d.barClass).css({background:p,width:n,position:"absolute",top:0,opacity:t,display:u?"block":"none","border-radius":n,BorderRadius:n,MozBorderRadius:n,WebkitBorderRadius:n,zIndex:99}),C=q=="right"?{right:r}:{left:r};A.css(C),B.css(C),y.wrap(z),y.parent().append(B),y.parent().append(A),B.draggable({axis:"y",containment:"parent",start:function(){e=!0},stop:function(){e=!1,I()},drag:function(b){E(0,a(this).position().top,!1)}}),A.hover(function(){H()},function(){I()}),B.hover(function(){c=!0},function(){c=!1}),y.hover(function(){b=!0,H(),I()},function(){b=!1,I()});var D=function(a){if(!!b){var a=a||window.event,c=0;a.wheelDelta&&(c=-a.wheelDelta/120),a.detail&&(c=a.detail/3),E(c,!0),a.preventDefault&&!j&&a.preventDefault(),j||(a.returnValue=!1)}},E=function(a,b,c){var d=a;if(b){d=parseInt(B.css("top"))+a*k,d=Math.max(d,0);var e=y.outerHeight()-B.outerHeight();d=Math.min(d,e),B.css({top:d+"px"})}var f=parseInt(B.css("top"))/(y.outerHeight()-B.outerHeight());d=f*(y[0].scrollHeight-y.outerHeight());if(c){d=a;var g=d/y[0].scrollHeight*y.outerHeight();B.css({top:g+"px"})}y.scrollTop(d),H(),I()},F=function(){window.addEventListener?(this.addEventListener("DOMMouseScroll",D,!1),this.addEventListener("mousewheel",D,!1)):document.attachEvent("onmousewheel",D)};F();var G=function(){g=Math.max(y.outerHeight()/y[0].scrollHeight*y.outerHeight(),i),B.css({height:g+"px"})};G();var H=function(){G(),clearTimeout(f);g>=y.outerHeight()?j=!0:(B.fadeIn("fast"),v&&A.fadeIn("fast"))},I=function(){u||(f=setTimeout(function(){!c&&!e&&(B.fadeOut("slow"),A.fadeOut("slow"))},1e3))};s=="bottom"?(B.css({top:"auto",bottom:0}),E(0,!0)):typeof s=="object"&&(E(a(s).position().top,null,!0),u||B.hide())});return this}}),jQuery.fn.extend({slimscroll:jQuery.fn.slimScroll})})(jQuery) \ No newline at end of file