如何在AngularJS中滚动到页面顶部? [英] How to scroll to top of the page in AngularJS?

查看:363
本文介绍了如何在AngularJS中滚动到页面顶部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在使用angularjs得到ajax调用响应后滚动到页面顶部.基本上,我会在页面顶部显示警报消息,并且我希望将警报消息集中在接收到的ajax响应上.

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.

谢谢

推荐答案

您可以使用

$window.scrollTo(x, y);

其中x是沿水平轴的像素,y是沿垂直轴的像素.

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

  1. 滚动到顶部

$window.scrollTo(0, 0);

  • 关注元素

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

  • Example

    更新:

    您还可以使用 $anchorScroll

    Also you can use $anchorScroll

    Example

    这篇关于如何在AngularJS中滚动到页面顶部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆