8

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?

1
  • Did you come across a solution to this? Thx! Commented Aug 10, 2014 at 8:23

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.