Created
August 28, 2015 00:56
-
-
Save mandelbro/b17f4be59a7197bec912 to your computer and use it in GitHub Desktop.
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("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