diff --git a/bower.json b/bower.json index 549efe9..af51196 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "ngSmoothScroll", - "version": "2.0.0", + "version": "2.0.1", "homepage": "https://github.com/d-oliveros/ngSmoothScroll", "authors": [ "David Oliveros " diff --git a/dist/angular-smooth-scroll.min.js b/dist/angular-smooth-scroll.min.js index 29e0e14..53294cd 100644 --- a/dist/angular-smooth-scroll.min.js +++ b/dist/angular-smooth-scroll.min.js @@ -1,16 +1,16 @@ /*! - * Angular Smooth Scroll (ngSmoothScroll) - * Animates scrolling to elements, by David Oliveros. + * Angular Smooth Scroll (ngSmoothScroll) + * Animates scrolling to elements, by David Oliveros. * * Callback hooks contributed by Ben Armston https://github.com/benarmston - * Easing support contributed by Willem Liu. https://github.com/willemliu - * Easing functions forked from Gaëtan Renaudeau. https://gist.github.com/gre/1650294 - * Infinite loop bugs in iOS and Chrome (when zoomed) by Alex Guzman. https://github.com/alexguzman - * Support for scrolling in custom containers by Joseph Matthias Goh. https://github.com/zephinzer - * Influenced by Chris Ferdinandi - * https://github.com/cferdinandi + * Easing support contributed by Willem Liu. https://github.com/willemliu + * Easing functions forked from Gaëtan Renaudeau. https://gist.github.com/gre/1650294 + * Infinite loop bugs in iOS and Chrome (when zoomed) by Alex Guzman. https://github.com/alexguzman + * Support for scrolling in custom containers by Joseph Matthias Goh. https://github.com/zephinzer + * Influenced by Chris Ferdinandi + * https://github.com/cferdinandi * - * Version: 2.0.0 - * License: MIT + * Version: 2.0.1 + * License: MIT */ -!function(){"use strict";var e=angular.module("smoothScroll",[]),t=function(e,t){t=t||{};var n=t.duration||800,c=t.offset||0,r=t.easing||"easeInOutQuart",a=t.callbackBefore||function(){},o=t.callbackAfter||function(){},l=document.getElementById(t.containerId)||null,u=void 0!=l&&null!=l,f=function(){return u?l.scrollTop:window.pageYOffset?window.pageYOffset:document.documentElement.scrollTop},i=function(e,t){switch(e){case"easeInQuad":return t*t;case"easeOutQuad":return t*(2-t);case"easeInOutQuad":return.5>t?2*t*t:-1+(4-2*t)*t;case"easeInCubic":return t*t*t;case"easeOutCubic":return--t*t*t+1;case"easeInOutCubic":return.5>t?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1;case"easeInQuart":return t*t*t*t;case"easeOutQuart":return 1- --t*t*t*t;case"easeInOutQuart":return.5>t?8*t*t*t*t:1-8*--t*t*t*t;case"easeInQuint":return t*t*t*t*t;case"easeOutQuint":return 1+--t*t*t*t*t;case"easeInOutQuint":return.5>t?16*t*t*t*t*t:1+16*--t*t*t*t*t;default:return t}},s=function(e){var t=0;if(e.offsetParent)do t+=e.offsetTop,e=e.offsetParent;while(e);return t=Math.max(t-c,0)};setTimeout(function(){var t,c,d,b,k=null,m=f(),I=s(e),v=0,g=I-m,h=function(){k=f(),u?(d=l.scrollHeight,b=l.clientHeight+k):(d=document.body.scrollheight,b=window.innerHeight+k),c!=I&&k!=I&&d>b||(clearInterval(A),o(e))},p=function(){v+=16,t=v/n,t=t>1?1:t,c=m+g*i(r,t),u?l.scrollTop=c:window.scrollTo(0,c),h()};a(e);var A=setInterval(p,16)},0)};e.factory("smoothScroll",function(){return t}),e.directive("smoothScroll",["smoothScroll",function(e){return{restrict:"A",scope:{callbackBefore:"&",callbackAfter:"&"},link:function(t,n,c){(void 0===c.scrollIf||"true"===c.scrollIf)&&setTimeout(function(){var r=function(e){if(c.callbackBefore){var n=t.callbackBefore({element:e});"function"==typeof n&&n(e)}},a=function(e){if(c.callbackAfter){var n=t.callbackAfter({element:e});"function"==typeof n&&n(e)}};e(n[0],{duration:c.duration,offset:c.offset,easing:c.easing,callbackBefore:r,callbackAfter:a,containerId:c.containerId})},0)}}}]),e.directive("scrollTo",["smoothScroll",function(e){return{restrict:"A",scope:{callbackBefore:"&",callbackAfter:"&"},link:function(t,n,c){var r;n.on("click",function(n){if(n.preventDefault(),r=document.getElementById(c.scrollTo)){var a=function(e){if(c.callbackBefore){var n=t.callbackBefore({element:e});"function"==typeof n&&n(e)}},o=function(e){if(c.callbackAfter){var n=t.callbackAfter({element:e});"function"==typeof n&&n(e)}};return e(r,{duration:c.duration,offset:c.offset,easing:c.easing,callbackBefore:a,callbackAfter:o,containerId:c.containerId}),!1}})}}}])}(); \ No newline at end of file +(function(){"use strict";var module=angular.module("smoothScroll",[]);var smoothScroll=function(element,options){options=options||{};var duration=options.duration||800,offset=options.offset||0,easing=options.easing||"easeInOutQuart",callbackBefore=options.callbackBefore||function(){},callbackAfter=options.callbackAfter||function(){},container=document.getElementById(options.containerId)||null,containerPresent=container!=undefined&&container!=null;var getScrollLocation=function(){if(containerPresent){return container.scrollTop}else{if(window.pageYOffset){return window.pageYOffset}else{return document.documentElement.scrollTop}}};var getEasingPattern=function(type,time){switch(type){case"easeInQuad":return time*time;case"easeOutQuad":return time*(2-time);case"easeInOutQuad":return time<.5?2*time*time:-1+(4-2*time)*time;case"easeInCubic":return time*time*time;case"easeOutCubic":return--time*time*time+1;case"easeInOutCubic":return time<.5?4*time*time*time:(time-1)*(2*time-2)*(2*time-2)+1;case"easeInQuart":return time*time*time*time;case"easeOutQuart":return 1- --time*time*time*time;case"easeInOutQuart":return time<.5?8*time*time*time*time:1-8*--time*time*time*time;case"easeInQuint":return time*time*time*time*time;case"easeOutQuint":return 1+--time*time*time*time*time;case"easeInOutQuint":return time<.5?16*time*time*time*time*time:1+16*--time*time*time*time*time;default: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};setTimeout(function(){var currentLocation=null,startLocation=getScrollLocation(),endLocation=getEndLocation(element),timeLapsed=0,distance=endLocation-startLocation,percentage,position,scrollHeight,internalHeight;var stopAnimation=function(){currentLocation=getScrollLocation();if(containerPresent){scrollHeight=container.scrollHeight;internalHeight=container.clientHeight+currentLocation}else{scrollHeight=document.body.scrollheight;internalHeight=window.innerHeight+currentLocation}if(position==endLocation||currentLocation==endLocation||internalHeight>scrollHeight){clearInterval(runAnimation);callbackAfter(element)}};var animateScroll=function(){timeLapsed+=16;percentage=timeLapsed/duration;percentage=percentage>1?1:percentage;position=startLocation+distance*getEasingPattern(easing,percentage);if(containerPresent){container.scrollTop=position}else{window.scrollTo(0,position)}stopAnimation()};callbackBefore(element);var runAnimation=setInterval(animateScroll,16)},0)};module.factory("smoothScroll",function(){return smoothScroll});module.directive("smoothScroll",["smoothScroll",function(smoothScroll){return{restrict:"A",scope:{callbackBefore:"&",callbackAfter:"&"},link:function($scope,$elem,$attrs){if(typeof $attrs.scrollIf==="undefined"||$attrs.scrollIf==="true"){setTimeout(function(){var callbackBefore=function(element){if($attrs.callbackBefore){var exprHandler=$scope.callbackBefore({element:element});if(typeof exprHandler==="function"){exprHandler(element)}}};var callbackAfter=function(element){if($attrs.callbackAfter){var exprHandler=$scope.callbackAfter({element:element});if(typeof exprHandler==="function"){exprHandler(element)}}};smoothScroll($elem[0],{duration:$attrs.duration,offset:$attrs.offset,easing:$attrs.easing,callbackBefore:callbackBefore,callbackAfter:callbackAfter,containerId:$attrs.containerId})},0)}}}}]);module.directive("scrollTo",["smoothScroll",function(smoothScroll){return{restrict:"A",scope:{callbackBefore:"&",callbackAfter:"&"},link:function($scope,$elem,$attrs){var targetElement;$elem.on("click",function(e){e.preventDefault();targetElement=document.getElementById($attrs.scrollTo);if(!targetElement)return;var callbackBefore=function(element){if($attrs.callbackBefore){var exprHandler=$scope.callbackBefore({element:element});if(typeof exprHandler==="function"){exprHandler(element)}}};var callbackAfter=function(element){if($attrs.callbackAfter){var exprHandler=$scope.callbackAfter({element:element});if(typeof exprHandler==="function"){exprHandler(element)}}};smoothScroll(targetElement,{duration:$attrs.duration,offset:$attrs.offset,easing:$attrs.easing,callbackBefore:callbackBefore,callbackAfter:callbackAfter,containerId:$attrs.containerId});return false})}}}])})(); \ No newline at end of file diff --git a/lib/angular-smooth-scroll.js b/lib/angular-smooth-scroll.js index df0c269..6d5b423 100644 --- a/lib/angular-smooth-scroll.js +++ b/lib/angular-smooth-scroll.js @@ -10,7 +10,7 @@ * Influenced by Chris Ferdinandi * https://github.com/cferdinandi * - * Version: 2.0.0 + * Version: 2.0.1 * License: MIT */ @@ -126,7 +126,9 @@ currentLocation == endLocation ) || ( // condition 3 - internalHeight >= scrollHeight + /// change >= to > + /// fixes #70 + internalHeight > scrollHeight ) ) { // stop clearInterval(runAnimation);