保留 AngularJS 中路由更改的滚动位置? [英] Retain scroll position on route change in AngularJS?

查看:28
本文介绍了保留 AngularJS 中路由更改的滚动位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例应用:http://angular.github.com/angular-phonecat/step-11/app/#/phones

如果您选择最后一个手机摩托罗拉魅力",它会显示手机的详细信息.当您在浏览器上导航回时,它会重新加载数据并且滚动位于顶部.

If you choose the last phone "Motorola charm" it will show you the details of the phone. When you navigate back with on your browser it reloads the data and scrolling is at the top.

返回导航时自动滚动到剩余位置的最佳方法是什么?而且,为什么 angular 会重新加载数据?

What is the best way to automatically scroll to where is was left when navigatin back? And also, why does angular reloads the data?

我的计算机上有相同的angular-phonecat"示例,并且我添加了一个无限滚动,它会在您滚动时加载更多数据.所以我真的不希望用户再次重新加载 50 多个项目或向下滚动 30 秒.

I have the same "angular-phonecat" sample on my computer and I have added an infinite scroll which loads more data as you scroll. So I really dont want the user to reload 50+ items again or scrolling down for 30 seconds.

推荐答案

我之前没用过,但是angular有个$anchorScroll 服务.至于重新加载数据,您可以使用 $cacheFactory 缓存它,或者将数据存储在更高的范围内.

I haven't used it before, but angular has a $anchorScroll service. As to reloading the data, you could cache it using $cacheFactory, or store the data on a higher scope.

这篇关于保留 AngularJS 中路由更改的滚动位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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