|
1 | 1 | /** |
2 | 2 | * angular-ui-utils - Swiss-Army-Knife of AngularJS tools (with no external dependencies!) |
3 | | - * @version v0.2.1 - 2015-02-10 |
| 3 | + * @version v0.2.1 - 2015-02-17 |
4 | 4 | * @link http://angular-ui.github.com |
5 | 5 | * @license MIT License, http://www.opensource.org/licenses/MIT |
6 | 6 | */ |
@@ -1925,26 +1925,36 @@ angular.module('ui.scrollfix',[]).directive('uiScrollfix', ['$window', function |
1925 | 1925 | return { |
1926 | 1926 | require: '^?uiScrollfixTarget', |
1927 | 1927 | link: function (scope, elm, attrs, uiScrollfixTarget) { |
1928 | | - var top = elm[0].offsetTop, |
| 1928 | + var absolute = true, |
| 1929 | + shift = 0, |
| 1930 | + fixLimit, |
1929 | 1931 | $target = uiScrollfixTarget && uiScrollfixTarget.$element || angular.element($window); |
1930 | 1932 |
|
1931 | 1933 | if (!attrs.uiScrollfix) { |
1932 | | - attrs.uiScrollfix = top; |
| 1934 | + absolute = false; |
1933 | 1935 | } else if (typeof(attrs.uiScrollfix) === 'string') { |
1934 | 1936 | // charAt is generally faster than indexOf: http://jsperf.com/indexof-vs-charat |
1935 | 1937 | if (attrs.uiScrollfix.charAt(0) === '-') { |
1936 | | - attrs.uiScrollfix = top - parseFloat(attrs.uiScrollfix.substr(1)); |
| 1938 | + absolute = false; |
| 1939 | + shift = - parseFloat(attrs.uiScrollfix.substr(1)); |
1937 | 1940 | } else if (attrs.uiScrollfix.charAt(0) === '+') { |
1938 | | - attrs.uiScrollfix = top + parseFloat(attrs.uiScrollfix.substr(1)); |
| 1941 | + absolute = false; |
| 1942 | + shift = parseFloat(attrs.uiScrollfix.substr(1)); |
1939 | 1943 | } |
1940 | 1944 | } |
1941 | 1945 |
|
| 1946 | + fixLimit = absolute ? attrs.uiScrollfix : elm[0].offsetTop + shift; |
| 1947 | + |
1942 | 1948 | function onScroll() { |
| 1949 | + |
| 1950 | + var limit = absolute ? attrs.uiScrollfix : elm[0].offsetTop + shift; |
| 1951 | + |
1943 | 1952 | // if pageYOffset is defined use it, otherwise use other crap for IE |
1944 | 1953 | var offset = uiScrollfixTarget ? $target[0].scrollTop : getWindowScrollTop(); |
1945 | | - if (!elm.hasClass('ui-scrollfix') && offset > attrs.uiScrollfix) { |
| 1954 | + if (!elm.hasClass('ui-scrollfix') && offset > limit) { |
1946 | 1955 | elm.addClass('ui-scrollfix'); |
1947 | | - } else if (elm.hasClass('ui-scrollfix') && offset < attrs.uiScrollfix) { |
| 1956 | + fixLimit = limit; |
| 1957 | + } else if (elm.hasClass('ui-scrollfix') && offset < fixLimit) { |
1948 | 1958 | elm.removeClass('ui-scrollfix'); |
1949 | 1959 | } |
1950 | 1960 | } |
|
0 commit comments