AngularJS + Safari浏览器:强制页面滚动到顶部时,页面切换 [英] AngularJS + Safari: Force page to scroll to top when pages switch

查看:888
本文介绍了AngularJS + Safari浏览器:强制页面滚动到顶部时,页面切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的,Safari浏览器,只能用AngularJS滚动行为。

I am having an odd, safari-only scrolling behavior using AngularJS.

每当用户页面之间翻转,页面被改变,如同它们是AJAX。我知道他们是在AngualrJS,但由此产生的行为是浏览器不滚动,当用户切换页面顶部。

Whenever the user flips between pages, the pages are being changed as if they are AJAX. I understand they are in AngualrJS, but the resulting behavior is that the browser does not scroll to top when the user switches pages.

我试图强制浏览器滚动到顶部时正在使用一个新的控制器,但它似乎并没有做任何事情。

I've tried to force the browser to scroll to top whenever a new controller is being used, but it does not seem to do anything.

我运行下面的JS在每个控制器的顶部:

I'm running the following JS at the top of every controller:

=的document.body.scrollTop document.documentElement.scrollTop = 0;

这也是Safari浏览器,只有错误,其他浏览器将滚动时,页面顶部的变化。有没有人遇到过类似的问题,或者想个更好的办法来解决呢?

This is also a Safari-only bug, every other browser will scroll to top when the page changes. Has anyone encountered a similar issue or think of a better way to resolve it?

推荐答案

您是否尝试过使用$ anchorScroll()?它这里记录

Have you tried using $anchorScroll()? it's documented here.

这篇关于AngularJS + Safari浏览器:强制页面滚动到顶部时,页面切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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