Scroll to top of div in AngularJS?

前端 未结 4 832
情深已故
情深已故 2021-02-03 18:39

I am using AngularJS for a small web app and have encountered a problem. I am using ng-repeat to populate a list inside of a div. The div has a fixed height and is

4条回答
  •  悲&欢浪女
    2021-02-03 19:31

    You can also use $anchorScroll as per the docs

    // set the location.hash to the id of
    // the element you wish to scroll to.
    $location.hash('bottom');
    
    // call $anchorScroll()
    $anchorScroll();
    

    You would need to wrap this within a $timeout:

    $timeout(function() {
      $location.hash('myList');
      $anchorScroll();
    })
    

提交回复
热议问题