Is there a way to get the functionality of ui-router
's autoscroll with smooth scrolling instead of jumping immediately to that place?
Or is there a way to add an eventlistener to all states that's fired when the state is changed in a way that I get access to the ui-view's element?
Something like this should work. You might have to tweak the target.offset().top a bit if you have a fixed header or something similar that might mess with the offset.
app.config(function ($provide) {
$provide.decorator('$uiViewScroll', function ($delegate) {
return function (uiViewElement) {
$('html,body').animate({
scrollTop: uiViewElement.offset().top
}, 500);
};
});
});
Keep autoscroll="true"
on your ui-view.
See other answer for credit on the prodiver: Angular ui-router scroll to top, not to ui-view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With