diff --git a/dist/ng-scrollbar.js b/dist/ng-scrollbar.js index 4fc9284..ccde394 100644 --- a/dist/ng-scrollbar.js +++ b/dist/ng-scrollbar.js @@ -74,6 +74,7 @@ angular.module('ngScrollbar', []).directive('ngScrollbar', [ redraw(); }; var buildScrollbar = function (rollToBottom) { + var parentOffsetTop = element[0].parentElement.offsetTop; var wheelEvent = win[0].onmousewheel !== undefined ? 'mousewheel' : 'DOMMouseScroll'; rollToBottom = flags.bottom || rollToBottom; mainElm = angular.element(element.children()[0]); @@ -82,7 +83,7 @@ angular.module('ngScrollbar', []).directive('ngScrollbar', [ thumb = angular.element(angular.element(tools.children()[0]).children()[0]); thumbLine = angular.element(thumb.children()[0]); track = angular.element(angular.element(tools.children()[0]).children()[1]); - page.height = element[0].offsetHeight; + page.height = element[0].offsetHeight - parentOffsetTop; page.scrollHeight = transculdedContainer[0].scrollHeight; if (page.height < page.scrollHeight) { scope.showYScrollbar = true; diff --git a/dist/ng-scrollbar.min.js b/dist/ng-scrollbar.min.js index 1a09264..ace8723 100644 --- a/dist/ng-scrollbar.min.js +++ b/dist/ng-scrollbar.min.js @@ -1,8 +1,8 @@ /** * ng-scrollbar - * @version v0.0.1 - 2014-05-13 + * @version v0.0.1 - 2014-05-14 * @link https://github.com/asafdav/ng-scrollbar * @author Asaf David <> * @license MIT License, http://www.opensource.org/licenses/MIT */ -"use strict";angular.module("ngScrollbar",[]).directive("ngScrollbar",["$parse","$window",function(a,b){return{restrict:"A",replace:!0,transclude:!0,link:function(a,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q={bottom:d.hasOwnProperty("bottom")},r=angular.element(b),s={top:0},t={top:0},u=function(){k={position:"relative",overflow:"hidden","max-width":"100%",height:"100%"},t.height&&(k.height=t.height+"px"),l={position:"absolute",height:s.height+"px",top:s.top+"px"},m={position:"relative","line-height":s.height+"px"},n={position:"relative",top:t.top+"px",overflow:"hidden"}},v=function(){h.css("top",s.top+"px");var a=s.top/t.height;t.top=-Math.round(t.scrollHeight*a),f.css("top",t.top+"px")},w=function(a){var b=a.hasOwnProperty("offsetY")?a.offsetY:a.layerY,c=Math.max(0,Math.min(parseInt(s.trackHeight,10)-parseInt(s.height,10),b));s.top=c,v(),a.stopPropagation()},x=function(a){var b=20,c=void 0!==a.wheelDeltaY?a.wheelDeltaY/b:void 0!==a.wheelDelta?a.wheelDelta/b:-a.detail*(b/10);return s.top=Math.max(0,Math.min(parseInt(t.height,10)-parseInt(s.height,10),parseInt(s.top,10)-c)),v(),a.preventDefault?void a.preventDefault():!1},y=function(a,b,c){s.top=Math.max(0,Math.min(parseInt(s.trackHeight,10)-parseInt(s.height,10),c)),a.stopPropagation()},z=function(a){var b=a.pageY-h[0].scrollTop-o,c=0;y(a,c,b),v()},A=function(b){var d=void 0!==r[0].onmousewheel?"mousewheel":"DOMMouseScroll";b=q.bottom||b,e=angular.element(c.children()[0]),f=angular.element(e.children()[0]),g=angular.element(e.children()[1]),h=angular.element(angular.element(g.children()[0]).children()[0]),i=angular.element(h.children()[0]),j=angular.element(angular.element(g.children()[0]).children()[1]),t.height=c[0].offsetHeight,t.scrollHeight=f[0].scrollHeight,t.height
'}}]); \ No newline at end of file +"use strict";angular.module("ngScrollbar",[]).directive("ngScrollbar",["$parse","$window",function(a,b){return{restrict:"A",replace:!0,transclude:!0,link:function(a,c,d){var e,f,g,h,i,j,k,l,m,n,o,p,q={bottom:d.hasOwnProperty("bottom")},r=angular.element(b),s={top:0},t={top:0},u=function(){k={position:"relative",overflow:"hidden","max-width":"100%",height:"100%"},t.height&&(k.height=t.height+"px"),l={position:"absolute",height:s.height+"px",top:s.top+"px"},m={position:"relative","line-height":s.height+"px"},n={position:"relative",top:t.top+"px",overflow:"hidden"}},v=function(){h.css("top",s.top+"px");var a=s.top/t.height;t.top=-Math.round(t.scrollHeight*a),f.css("top",t.top+"px")},w=function(a){var b=a.hasOwnProperty("offsetY")?a.offsetY:a.layerY,c=Math.max(0,Math.min(parseInt(s.trackHeight,10)-parseInt(s.height,10),b));s.top=c,v(),a.stopPropagation()},x=function(a){var b=20,c=void 0!==a.wheelDeltaY?a.wheelDeltaY/b:void 0!==a.wheelDelta?a.wheelDelta/b:-a.detail*(b/10);return s.top=Math.max(0,Math.min(parseInt(t.height,10)-parseInt(s.height,10),parseInt(s.top,10)-c)),v(),a.preventDefault?void a.preventDefault():!1},y=function(a,b,c){s.top=Math.max(0,Math.min(parseInt(s.trackHeight,10)-parseInt(s.height,10),c)),a.stopPropagation()},z=function(a){var b=a.pageY-h[0].scrollTop-o,c=0;y(a,c,b),v()},A=function(b){var d=c[0].parentElement.offsetTop,p=void 0!==r[0].onmousewheel?"mousewheel":"DOMMouseScroll";b=q.bottom||b,e=angular.element(c.children()[0]),f=angular.element(e.children()[0]),g=angular.element(e.children()[1]),h=angular.element(angular.element(g.children()[0]).children()[0]),i=angular.element(h.children()[0]),j=angular.element(angular.element(g.children()[0]).children()[1]),t.height=c[0].offsetHeight-d,t.scrollHeight=f[0].scrollHeight,t.height
'}}]); \ No newline at end of file diff --git a/src/ng-scrollbar.js b/src/ng-scrollbar.js index ddff065..daadc75 100644 --- a/src/ng-scrollbar.js +++ b/src/ng-scrollbar.js @@ -112,6 +112,9 @@ angular.module('ngScrollbar', []). var buildScrollbar = function(rollToBottom) { + // Getting top position of a parent element to place scroll correctly + var parentOffsetTop = element[0].parentElement.offsetTop; + var wheelEvent = win[0].onmousewheel !== undefined ? 'mousewheel' : 'DOMMouseScroll'; rollToBottom = flags.bottom || rollToBottom; @@ -123,7 +126,7 @@ angular.module('ngScrollbar', []). track = angular.element(angular.element(tools.children()[0]).children()[1]); // Check if scroll bar is needed - page.height = element[0].offsetHeight ; + page.height = element[0].offsetHeight - parentOffsetTop; page.scrollHeight = transculdedContainer[0].scrollHeight; if (page.height < page.scrollHeight) {