diff --git a/modules/scrollfix/scrollfix.js b/modules/scrollfix/scrollfix.js index 77be62bd..fc27b78d 100644 --- a/modules/scrollfix/scrollfix.js +++ b/modules/scrollfix/scrollfix.js @@ -6,6 +6,14 @@ * Takes 300 (absolute) or -300 or +300 (relative to detected) */ angular.module('ui.scrollfix',[]).directive('uiScrollfix', ['$window', function ($window) { + function getWindowScrollTop() { + if (angular.isDefined($window.pageYOffset)) { + return $window.pageYOffset; + } else { + var iebody = (document.compatMode && document.compatMode !== 'BackCompat') ? document.documentElement : document.body; + return iebody.scrollTop; + } + } return { require: '^?uiScrollfixTarget', link: function (scope, elm, attrs, uiScrollfixTarget) { @@ -25,13 +33,7 @@ angular.module('ui.scrollfix',[]).directive('uiScrollfix', ['$window', function function onScroll() { // if pageYOffset is defined use it, otherwise use other crap for IE - var offset; - if (angular.isDefined($window.pageYOffset)) { - offset = $window.pageYOffset; - } else { - var iebody = (document.compatMode && document.compatMode !== 'BackCompat') ? document.documentElement : document.body; - offset = iebody.scrollTop; - } + var offset = uiScrollfixTarget ? $target[0].scrollTop : getWindowScrollTop(); if (!elm.hasClass('ui-scrollfix') && offset > attrs.uiScrollfix) { elm.addClass('ui-scrollfix'); } else if (elm.hasClass('ui-scrollfix') && offset < attrs.uiScrollfix) { diff --git a/modules/scrollfix/test/scrollfixSpec.js b/modules/scrollfix/test/scrollfixSpec.js index c89e717f..d09d0b0e 100644 --- a/modules/scrollfix/test/scrollfixSpec.js +++ b/modules/scrollfix/test/scrollfixSpec.js @@ -53,4 +53,21 @@ describe('uiScrollfix', function () { expect(element.hasClass('ui-scrollfix')).toBe(false); }); }); + describe('scrolling the target', function() { + var target, element; + beforeEach(function() { + target = $compile('