AngularJS: Scroll to end of element after applying DOM changes

前端 未结 6 957
攒了一身酷
攒了一身酷 2020-12-29 20:16

I have a simple list of items. I want to be able to scroll to the bottom of the element displaying the items whenever I add more items. I understood there is no way of hooki

6条回答
  •  春和景丽
    2020-12-29 20:57

    You could create a simple directive that bind a click handler that scrolls the

      to the bottom each time.

      myApp.directive("scrollBottom", function(){
          return {
              link: function(scope, element, attr){
                  var $id= $("#" + attr.scrollBottom);
                  $(element).on("click", function(){
                      $id.scrollTop($id[0].scrollHeight);
                  });
              }
          }
      });
      

      example on jsfiddle

提交回复
热议问题