最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular: disable scroll to top when changing view - Stack Overflow

programmeradmin0浏览0评论

Say I have a large header so that the ng-view directive is down on the page. just before this ng-view I have a kind of menu who trigger angular routing and so change the view. My problem is that anytime the routing is trigged the page keep scroll to top so the partial is out of the viewport.

here is my routing:

angular.module('portfolio', [])
  .config(function ($routeProvider, $anchorScrollProvider) {
    $anchorScrollProvider.disableAutoScrolling();
    $routeProvider
      .when('', {
        templateUrl: 'portfolio/index.html',
        controller: 'PortfolioListCtrl'
      })
      .when('/portfolio/:project', {
        templateUrl: 'portfolio/detail.html',
        controller: 'PortfolioDetailCtrl'
      })
      .otherwise({redirectTo: ''});
  });

I have $anchorScrollProvider.disableAutoScrolling(); put it doesn't seems to work.

Anyone have an idea?

Say I have a large header so that the ng-view directive is down on the page. just before this ng-view I have a kind of menu who trigger angular routing and so change the view. My problem is that anytime the routing is trigged the page keep scroll to top so the partial is out of the viewport.

here is my routing:

angular.module('portfolio', [])
  .config(function ($routeProvider, $anchorScrollProvider) {
    $anchorScrollProvider.disableAutoScrolling();
    $routeProvider
      .when('', {
        templateUrl: 'portfolio/index.html',
        controller: 'PortfolioListCtrl'
      })
      .when('/portfolio/:project', {
        templateUrl: 'portfolio/detail.html',
        controller: 'PortfolioDetailCtrl'
      })
      .otherwise({redirectTo: ''});
  });

I have $anchorScrollProvider.disableAutoScrolling(); put it doesn't seems to work.

Anyone have an idea?

Share Improve this question asked May 29, 2013 at 18:58 ThomasThomas 752 silver badges5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

The docs are a bit confusing on this one, I remember having the same problem. Apparently ng-view uses the $anchorScroll service, so you can disable it by simply overwriting it in your module:

angular.module('portfolio').value('$anchorScroll', angular.noop);
发布评论

评论列表(0)

  1. 暂无评论