这听起来像你想要使用HTML历史API,如window.history.pushState()
和window.history.popState()
。这听起来像你想使用浏览器滚动。
快速谷歌搜索发现我this documentation about $location 和this documentation about scrolling从AngularJS文档。
我不知道如何在AngularJS做到这一点,但在jQuery的你可以用pushState()
到一个特定的URL添加到浏览器的历史记录(这可能是你的同一个页面上的#),然后你可以添加一个popState()
处理程序,当用户单击后退按钮时,将执行刷新页面以外的操作。
例如
$(document).on('load',function(){
window.history.replaceState({element: {positionY: 0}},"load",location.pathname);
});
$(mylink).click(function(evt){
// something like: window.history.pushState(evt.target);
});
// this occurs when the user clicks the back button
$(document).on("popstate", function(evt) {
evt.preventDefault(); // prevents page refresh
var state = evt.originalEvent.state;
window.scrollTo(0,state.element.positionY);
}
的可能的复制[保留在AngularJS路由改变滚动位置?](https://stackoverflow.com/questions/14107531/retain-scroll-position-on-route-change -in-angularjs) – azerafati