Repository navigation
Expand file tree
/
Copy pathangular-smooth-scroll.min.js
More file actions
1 lines (1 loc) · 2.16 KB
/
Copy pathangular-smooth-scroll.min.js
File metadata and controls
1 lines (1 loc) · 2.16 KB
1
angular.module("smoothScroll",[]).directive("smoothScroll",["$timeout","smoothScroll",function(e,t){return{restrict:"A",scope:{callbackBefore:"&",callbackAfter:"&"},link:function(n,o,a){e(function(){if(void 0===a.scrollIf||"true"===a.scrollIf){var e=function(e){if(a.callbackBefore){var t=n.callbackBefore({element:e});"function"==typeof t&&t(e)}},c=function(e){if(a.callbackAfter){var t=n.callbackAfter({element:e});"function"==typeof t&&t(e)}};t(o[0],{duration:a.duration,offset:a.offset,easing:a.easing,callbackBefore:e,callbackAfter:c})}})}}}]).directive("scrollTo",["smoothScroll",function(e){return{restrict:"A",scope:{callbackBefore:"&",callbackAfter:"&"},link:function(t,n,o){var a;n.on("click",function(n){if(a=document.getElementById(o.scrollTo)){n.preventDefault();var c=function(e){if(o.callbackBefore){var n=t.callbackBefore({element:e});"function"==typeof n&&n(e)}},r=function(e){if(o.callbackAfter){var n=t.callbackAfter({element:e});"function"==typeof n&&n(e)}};return e(a,{duration:o.duration,offset:o.offset,easing:o.easing,callbackBefore:c,callbackAfter:r}),!1}})}}}]).factory("smoothScroll",["$timeout",function(e){var t=function(){return window.pageYOffset?window.pageYOffset:document.documentElement.scrollTop},n=function(n,o){e(function(){var e,a,c=t(),r=0;o=o||{};var f=o.duration||800,l=o.offset||0,u=o.easing||"easeInOutQuart",i=o.callbackBefore||function(){},s=o.callbackAfter||function(){},d=function(e,t){return"easeInQuad"==e?t*t:"easeOutQuad"==e?t*(2-t):"easeInOutQuad"==e?.5>t?2*t*t:-1+(4-2*t)*t:"easeInCubic"==e?t*t*t:"easeOutCubic"==e?--t*t*t+1:"easeInOutCubic"==e?.5>t?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1:"easeInQuart"==e?t*t*t*t:"easeOutQuart"==e?1- --t*t*t*t:"easeInOutQuart"==e?.5>t?8*t*t*t*t:1-8*--t*t*t*t:"easeInQuint"==e?t*t*t*t*t:"easeOutQuint"==e?1+--t*t*t*t*t:"easeInOutQuint"==e?.5>t?16*t*t*t*t*t:1+16*--t*t*t*t*t:t},b=function(e){var t=0;if(e.offsetParent)do t+=e.offsetTop,e=e.offsetParent;while(e);return t=Math.max(t-l,0)},k=b(n),m=k-c,v=function(){var e=t();a!=k&&e!=k&&window.innerHeight+e<document.body.scrollHeight||(clearInterval(g),s(n))},I=function(){r+=16,e=r/f,e=e>1?1:e,a=c+m*d(u,e),window.scrollTo(0,a),v()};i(n);var g=setInterval(I,16)})};return n}]);