-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathangular-scrollto.js
33 lines (29 loc) · 1.06 KB
/
angular-scrollto.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
angular.module('scrollto', []);
angular.module('scrollto')
.directive('scrollTo', ['$timeout', function ($timeout) {
function scroll (settings) {
return function () {
var scrollPane = angular.element(settings.container);
var scrollTo = (typeof settings.scrollTo == "number") ? settings.scrollTo : angular.element(settings.scrollTo);
var scrollY = (typeof scrollTo == "number") ? scrollTo : scrollTo.offset().top - settings.offset;
scrollPane.animate({scrollTop : scrollY }, settings.duration, settings.easing, function(){
if (typeof callback == 'function') { callback.call(this); }
});
}
}
return {
restrict: 'A',
link: function (scope, element, attrs) {
var settings = angular.extend({
container: 'html, body',
scrollTo: angular.element(),
offset: 0,
duration: 150,
easing: 'swing'
}, attrs);
element.on('click', function () {
$timeout(scroll(settings));
});
}
};
}]);