From a22fd45c882606e51169e5c635660a52a31c758e Mon Sep 17 00:00:00 2001 From: Clayton Ferris Date: Wed, 2 Apr 2014 15:32:25 -0700 Subject: [PATCH] IE8 compatability fix for missing window.pageYOffset --- angular-smooth-scroll-1.6.0.js | 10 +++++++--- angular-smooth-scroll-1.6.0.min.js | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/angular-smooth-scroll-1.6.0.js b/angular-smooth-scroll-1.6.0.js index 13e9c7f..e2250d2 100644 --- a/angular-smooth-scroll-1.6.0.js +++ b/angular-smooth-scroll-1.6.0.js @@ -78,9 +78,13 @@ angular.module('smoothScroll', []) // .factory('smoothScroll', ['$timeout', function($timeout){ + var getScrollLocation = function() { + return window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop; + }; + var smoothScroll = function (element, options) { $timeout(function(){ - var startLocation = window.pageYOffset, + var startLocation = getScrollLocation(), timeLapsed = 0, percentage, position; @@ -132,7 +136,7 @@ angular.module('smoothScroll', []) // Stop the scrolling animation when the anchor is reached (or at the top/bottom of the page) // var stopAnimation = function () { - var currentLocation = window.pageYOffset; + var currentLocation = getScrollLocation(); if ( position == endLocation || currentLocation == endLocation || ( (window.innerHeight + currentLocation) >= document.body.scrollHeight ) ) { clearInterval(runAnimation); } @@ -158,4 +162,4 @@ angular.module('smoothScroll', []) }; return smoothScroll; -}]); \ No newline at end of file +}]); diff --git a/angular-smooth-scroll-1.6.0.min.js b/angular-smooth-scroll-1.6.0.min.js index 55aa800..03aede2 100644 --- a/angular-smooth-scroll-1.6.0.min.js +++ b/angular-smooth-scroll-1.6.0.min.js @@ -1 +1 @@ -angular.module("smoothScroll",[]).directive("smoothScroll",["$timeout","smoothScroll",function(t,e){return{restrict:"A",link:function(n,o,r){t(function(){(void 0===r.scrollIf||"true"===r.scrollIf)&&e(o[0],{duration:r.duration,offset:r.offset,easing:r.easing})})}}}]).directive("scrollTo",["smoothScroll",function(t){return{restrict:"A",link:function(e,n,o){var r;n.on("click",function(e){return r=document.getElementById(o.scrollTo),r?(e.preventDefault(),t(r,{duration:o.duration,offset:o.offset,easing:o.easing}),!1):void 0})}}}]).factory("smoothScroll",["$timeout",function(t){var e=function(e,n){t(function(){var t,o,r=window.pageYOffset,u=0;n=n||{};var i=n.duration||800,a=n.offset||0,s=n.easing||"easeInOutQuart",f=function(t,e){return"easeInQuad"==t?e*e:"easeOutQuad"==t?e*(2-e):"easeInOutQuad"==t?.5>e?2*e*e:-1+(4-2*e)*e:"easeInCubic"==t?e*e*e:"easeOutCubic"==t?--e*e*e+1:"easeInOutCubic"==t?.5>e?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1:"easeInQuart"==t?e*e*e*e:"easeOutQuart"==t?1- --e*e*e*e:"easeInOutQuart"==t?.5>e?8*e*e*e*e:1-8*--e*e*e*e:"easeInQuint"==t?e*e*e*e*e:"easeOutQuint"==t?1+--e*e*e*e*e:"easeInOutQuint"==t?.5>e?16*e*e*e*e*e:1+16*--e*e*e*e*e:e},c=function(t){var e=0;if(t.offsetParent)do e+=t.offsetTop,t=t.offsetParent;while(t);return e=Math.max(e-a,0)},l=c(e),d=l-r,I=function(){var t=window.pageYOffset;o!=l&&t!=l&&window.innerHeight+t1?1:t,o=r+d*f(s,t),window.scrollTo(0,o),I()},m=setInterval(v,16)})};return e}]); \ No newline at end of file +angular.module("smoothScroll",[]).directive("smoothScroll",["$timeout","smoothScroll",function($timeout,smoothScroll){return{restrict:"A",link:function($scope,$elem,$attrs){$timeout(function(){if(typeof $attrs.scrollIf==="undefined"||$attrs.scrollIf==="true"){smoothScroll($elem[0],{duration:$attrs.duration,offset:$attrs.offset,easing:$attrs.easing})}})}}}]).directive("scrollTo",["smoothScroll",function(smoothScroll){return{restrict:"A",link:function($scope,$elem,$attrs){var targetElement;$elem.on("click",function(e){targetElement=document.getElementById($attrs.scrollTo);if(targetElement){e.preventDefault();smoothScroll(targetElement,{duration:$attrs.duration,offset:$attrs.offset,easing:$attrs.easing});return false}})}}}]).factory("smoothScroll",["$timeout",function($timeout){var getScrollLocation=function(){return window.pageYOffset?window.pageYOffset:document.documentElement.scrollTop};var smoothScroll=function(element,options){$timeout(function(){var startLocation=getScrollLocation(),timeLapsed=0,percentage,position;options=options||{};var duration=options.duration||800,offset=options.offset||0,easing=options.easing||"easeInOutQuart";var easingPattern=function(type,time){if(type=="easeInQuad")return time*time;if(type=="easeOutQuad")return time*(2-time);if(type=="easeInOutQuad")return time<.5?2*time*time:-1+(4-2*time)*time;if(type=="easeInCubic")return time*time*time;if(type=="easeOutCubic")return--time*time*time+1;if(type=="easeInOutCubic")return time<.5?4*time*time*time:(time-1)*(2*time-2)*(2*time-2)+1;if(type=="easeInQuart")return time*time*time*time;if(type=="easeOutQuart")return 1- --time*time*time*time;if(type=="easeInOutQuart")return time<.5?8*time*time*time*time:1-8*--time*time*time*time;if(type=="easeInQuint")return time*time*time*time*time;if(type=="easeOutQuint")return 1+--time*time*time*time*time;if(type=="easeInOutQuint")return time<.5?16*time*time*time*time*time:1+16*--time*time*time*time*time;return time};var getEndLocation=function(element){var location=0;if(element.offsetParent){do{location+=element.offsetTop;element=element.offsetParent}while(element)}location=Math.max(location-offset,0);return location};var endLocation=getEndLocation(element);var distance=endLocation-startLocation;var stopAnimation=function(){var currentLocation=getScrollLocation();if(position==endLocation||currentLocation==endLocation||window.innerHeight+currentLocation>=document.body.scrollHeight){clearInterval(runAnimation)}};var animateScroll=function(){timeLapsed+=16;percentage=timeLapsed/duration;percentage=percentage>1?1:percentage;position=startLocation+distance*easingPattern(easing,percentage);window.scrollTo(0,position);stopAnimation()};var runAnimation=setInterval(animateScroll,16)})};return smoothScroll}]); \ No newline at end of file