当用户使用mCustomScrollbar onTotalScroll达到结束滚动时,如何加载内容?

时间:2017-10-11 00:48:27

标签: javascript jquery angularjs

我在mTustomScrollBar onToTalScroll上附加内容时遇到错误。我想在到达结束滚动时加载内容。

控制器

$scope.initialize = function(){
        $('#sent').mCustomScrollbar({
            scrollInertia: 350,
            callbacks:{
                onTotalScroll:function(){
                    $scope.showMore();
                }
            }
        });

    };

我有错误“无法读取未定义的属性'childNodes'

1 个答案:

答案 0 :(得分:1)

app.directive("whenScrolled", function(){
   return{

      restrict: 'A',
      link: function(scope, elem, attrs){

     // we get a list of elements of size 1 and need the first element
     raw = elem[0];

     // we load more elements when scrolled past a limit
     elem.bind("scroll", function(){
       if(raw.scrollTop+raw.offsetHeight+5 >= raw.scrollHeight){
         scope.loading = true;

       // we can give any function which loads more elements into the list
         scope.$apply(attrs.whenScrolled);
       }
     });
   }
  }
});

https://codepen.io/headmax/pen/LzrpyP