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..8e08200 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 e=angular.module("smoothScroll",[]),t=function(e,t){t=t||{};var n=t.duration||800,r=t.offset||0,c=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-r,0)};setTimeout(function(){var t,r,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),(r==I||k==I||b>=d)&&(clearInterval(A),o(e))},p=function(){v+=16,t=v/n,t=t>1?1:t,r=Math.floor(m+g*i(c,t)),u?l.scrollTop=r:window.scrollTo(0,r),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,r){("undefined"==typeof r.scrollIf||"true"===r.scrollIf)&&setTimeout(function(){var c=function(e){if(r.callbackBefore){var n=t.callbackBefore({element:e});"function"==typeof n&&n(e)}},a=function(e){if(r.callbackAfter){var n=t.callbackAfter({element:e});"function"==typeof n&&n(e)}};e(n[0],{duration:r.duration,offset:r.offset,easing:r.easing,callbackBefore:c,callbackAfter:a,containerId:r.containerId})},0)}}}]),e.directive("scrollTo",["smoothScroll",function(e){return{restrict:"A",scope:{callbackBefore:"&",callbackAfter:"&"},link:function(t,n,r){var c;n.on("click",function(n){if(n.preventDefault(),c=document.getElementById(r.scrollTo)){var a=function(e){if(r.callbackBefore){var n=t.callbackBefore({element:e});"function"==typeof n&&n(e)}},o=function(e){if(r.callbackAfter){var n=t.callbackAfter({element:e});"function"==typeof n&&n(e)}};return e(c,{duration:r.duration,offset:r.offset,easing:r.easing,callbackBefore:a,callbackAfter:o,containerId:r.containerId}),!1}})}}}])}(); \ No newline at end of file diff --git a/lib/angular-smooth-scroll.js b/lib/angular-smooth-scroll.js index df0c269..5cc1a12 100644 --- a/lib/angular-smooth-scroll.js +++ b/lib/angular-smooth-scroll.js @@ -141,7 +141,7 @@ timeLapsed += 16; percentage = ( timeLapsed / duration ); percentage = ( percentage > 1 ) ? 1 : percentage; - position = startLocation + ( distance * getEasingPattern(easing, percentage) ); + position = Math.floor(startLocation + ( distance * getEasingPattern(easing, percentage) )); if(containerPresent) { container.scrollTop = position; } else {