Skip to content

Instantly share code, notes, and snippets.

@mandelbro
Created August 28, 2015 00:56
Show Gist options
  • Save mandelbro/b17f4be59a7197bec912 to your computer and use it in GitHub Desktop.
Save mandelbro/b17f4be59a7197bec912 to your computer and use it in GitHub Desktop.
app.directive("scrollToOnLoad", [
'$location',
function( $location ) {
return {
restrict: "A",
link: function(scope, element, attributes) {
var scrollTo = $location.hash() === attributes.id;
// scroll to the top of the posting with a padding for the header
if(scrollTo) {
$(window).on('load', function () {
window.scrollTo(0,Math.round(element.offset().top));
});
}
}
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment