Skip to content

Instantly share code, notes, and snippets.

@jchaney01
Created August 1, 2013 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchaney01/6127665 to your computer and use it in GitHub Desktop.
Save jchaney01/6127665 to your computer and use it in GitHub Desktop.
Angular directives for scrolling to an element and to the bottom of the page. Just add to an element and clicking the element will do it.
app.directive('scrollTo', ['$document',function ($document) {
var body = $($document[0].body);
return function (scope, element, attributes) {
var target = angular.element(attributes.scrollTo);
setTimeout(function () {
element.bind('click touchstart', function(e) {
e.preventDefault();
body.animate({scrollTop:target.offset().top},2000);
});
});
}
}]);
app.directive('bottomScroll', ['$document',function ($document) {
var body = $($document[0].body);
var targetHeight = $($document[0]).height();
return function (scope, element, attributes) {
var target = angular.element(attributes.scrollTo);
setTimeout(function () {
element.bind('click touchstart', function(e) {
e.preventDefault();
body.animate({scrollTop:targetHeight},2000);
});
});
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment