Created
August 1, 2013 01:06
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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