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

标签 javascript jquery angularjs

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

Controller

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

    };

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

最佳答案

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

关于javascript - 当用户使用 mCustomScrollbar onTotalScroll 到达结束滚动时,如何加载内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46678052/

相关文章:

javascript - x 秒后自动打开 Bootstrap Modal

javascript - HTML 类似命令行的文本框

javascript - 如何获取html对象将其作为AngularJS中的变量传递

javascript - 在对 AngularJS Controller 进行单元测试时如何模拟网络延迟?

javascript - 调用await jquery.ajax时如何获取数据、textStatus和jqXHR?

javascript - 如何禁用 s :select dynamically

javascript - 如果重构,重构 AJAX 调用将不起作用

angularjs - 如何手动安装 selenium webdriver-manager?

javascript - 如何在 Angular2 中使用/包含 fabricjs

jquery - $.getJSON 不返回 MVC3 的响应