Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smooth Scrolling for Autoscroll in UI-Router

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?

like image 634
nocksock Avatar asked Feb 07 '14 16:02

nocksock


1 Answers

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.

like image 161
Dustin Avatar answered Oct 18 '22 03:10

Dustin