0

I'm using ui-scroll-to

I need to scroll this smoothly. also it should stop before 100px in mentioned element.

<a ui-scroll-to="msg-container" >
   Go to Msg
</a>

<div id="msg-container">
   msgs
</div>

smooth scroll like .scrollTop() in jquery

1
  • 1
    u can just use jquery i don't think angular has something like that. I had the same problem and I've used jQuery. Another alternative is to make your own directive with does the scroll with jquery so you can use it in different places Commented Jan 4, 2016 at 7:24

1 Answer 1

0

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.

1 Comment

in HTML how to I use? Also I have fixed header.

Your Answer

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