• 滚屏加载


    滚屏加载
    
    另外一种可行的性能解决方案就是滚屏加载,又称”Endless Scrolling,“ “unpagination”,这是用于大量数据集显示的时候,
    又不想表格分页,所以一般放在页面最底部,当滚动屏幕到达页面底部的时候,就会尝试加载一个序列的数据集,追加在页面底部。
    在Angular社区有开源组件ngInfiniteScroll http:
    //binarymuse.github.io/ngInfiniteScroll/index.html实现滚屏加载。下面是官方Demo: HTML: <div ng-app='myApp' ng-controller='DemoController'> <div infinite-scroll='reddit.nextPage()' infinite-scroll-disabled='reddit.busy' infinite-scroll-distance='1'> <div ng-repeat='item in reddit.items'> <span class='score'>{{item.score}}</span> <span class='title'> <a ng-href='{{item.url}}' target='_blank'>{{item.title}}</a> </span> <small>by {{item.author}} - <a ng-href='http://reddit.com{{item.permalink}}' target='_blank'>{{item.num_comments}} comments</a> </small> <div style='clear: both;'></div> </div> <div ng-show='reddit.busy'>Loading data...</div> </div> </div> JavaScript: var myApp = angular.module('myApp', ['infinite-scroll']); myApp.controller('DemoController', ['$scope', 'Reddit', function($scope, Reddit) { $scope.reddit = new Reddit(); }]); // Reddit constructor function to encapsulate HTTP and pagination logic myApp.factory('Reddit', ['$http', function($http) { var Reddit = function() { this.items = []; this.busy = false; this.after = ''; }; Reddit.prototype.nextPage = function() { if (this.busy) return; this.busy = true; var url = 'http://api.reddit.com/hot?after=' + this.after + '&jsonp=JSON_CALLBACK'; $http.jsonp(url).success(function(data) { var items = data.data.children; for (var i = 0; i < items.length; i++) { this.items.push(items[i].data); } this.after = 't3_' + this.items[this.items.length - 1].id; this.busy = false; }.bind(this)); }; return Reddit; }]);
  • 相关阅读:
    实现vue项目改造服务端渲染
    vue项目seo问题简单解决,并生成sitemap
    vue element-table滚动条样式修改
    vue全局注册事件
    获取浏览器数据
    vscode配置,vue开发环境
    在项目中使用facebook聊天插件
    linux配置nuxt项目
    Vue中实现div编辑效果,及contenteditable设置为plaintext-only与true的区别
    js中判断对象是否存在
  • 原文地址:https://www.cnblogs.com/sxz2008/p/6581002.html
Copyright © 2020-2023  润新知