Nutty Programmer Nutty Programmer - 1 year ago 218
AngularJS Question

How to scroll to top of the page in AngularJS?

I want to scroll to the top of the page after getting an ajax call response using angularjs. Basically, I am displaying alert messages on top of the page and I want to focus the alert message as the ajax response received.


Answer Source

You can use

$window.scrollTo(x, y);

where x is the pixel along the horizontal axis and y is the pixel along the vertical axis.

1.Scroll to top

$window.scrollTo(0, 0);

2.Focus on element

$window.scrollTo(0, angular.element('put here your element').offsetTop);   


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download