Angularjs 滾動(dòng)加載更多數(shù)據(jù)
下面的例子只是為了簡單記錄怎么使用angularjs來實(shí)現(xiàn)滾動(dòng)加載數(shù)據(jù),具體的還是需要具體看待:
Javascript部分的controller
app.controller('AnalysizerCtrl', ['$scope', '$timeout', '$window',
function ($scope, $timeout, $window) {
$scope.showData = false;
$scope.isLoadingPIG = false;
$scope.isLoadingUJ = false;
$scope.isLoadingBoxSummary = false;
$scope.LoadingData = function (index) {
$scope.showData = true;
var pigHeight = $(".analysisContainer")[1].children[1].scrollHeight;
var ujHeight = $(".analysisContainer")[1].children[2].scrollHeight;
var boxSummaryHeight = $(".analysisContainer")[1].children[3].scrollHeight;
if (index == 0) {
//$scope.reLoadData = true;
pigHeight = 0;
ujHeight = 0;
$scope.gridOptions.data = null;
}
var showSummaryBox = function () {
$scope.isLoadingBoxSummary = false;
}
var showUj = function () {
$scope.isLoadingUJ = false;
//$scope.isLoadingSummaryBox = true;
//$timeout(showSummaryBox, 1000);
}
var showPig = function () {
$scope.isLoadingPIG = false;
//$scope.isLoadingUJ = false;
//$timeout(showUj, 10000);
}
if (pigHeight == 0) {
$scope.isLoadingPIG = true;
$timeout(showPig, 1000);
} else if (ujHeight == 0) {
$scope.isLoadingUJ = true;
$timeout(showUj, 1000);
} else if (boxSummaryHeight == 0) {
$scope.isLoadingBoxSummary = true;
$timeout(showSummaryBox, 1000);
}
};
}]
).directive('whenScrollEnd', function () {
return function (scope, elm, attr) {
var pageWindow = $(this);
pageWindow.bind('scroll', function (et, ed, pb) {
var winScrollTop = pageWindow.scrollTop();
var winHeight = pageWindow.height();
var maxScrollHeight = $(".analysisContainer")[1].scrollHeight;
if ((winScrollTop + winHeight) > maxScrollHeight) {
scope.$apply(attr.whenScrollEnd);
}
});
}
});
下面是HTML部分:
<div class="analysisContainer" ng-show="showData" when-scroll-end="LoadingData()"> <div id="b" ng-show="isLoadingPIG" style="width: 100%; text-align: center; z-index: 1"> <h6 class="loading"> <img src="~/Content/Images/loading2.gif" /> Loading Win & Convert data... </h6> </div> <div id="a" ng-show="!isLoadingPIG"> <img src="~/2016-03-16_152323.png" /> </div> <div ng-show="!isLoadingUJ"> <img src="~/2016-03-16_153347.png" /> </div> <div ng-show="!isLoadingBoxSummary"> <img src="~/2016-03-16_153404.png" /> </div> </div>
重要的部分是指令(directive)和滾動(dòng)時(shí)要加載數(shù)據(jù)的部分。
Angularjs 滾動(dòng)加載更多數(shù)據(jù)的相關(guān)知識(shí),小編就給大家介紹這么多,希望對大家有所幫助!
相關(guān)文章
Angular 2.0+ 的數(shù)據(jù)綁定的實(shí)現(xiàn)示例
本篇文章主要介紹了Angular 2.0+ 的數(shù)據(jù)綁定的實(shí)現(xiàn)實(shí)例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08
angular實(shí)現(xiàn)頁面打印局部功能的思考與方法
這篇文章主要給大家介紹了關(guān)于angular實(shí)現(xiàn)頁面打印局部功能的思考與方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-04-04
AngularJS學(xué)習(xí)筆記之表單驗(yàn)證功能實(shí)例詳解
這篇文章主要介紹了AngularJS學(xué)習(xí)筆記之表單驗(yàn)證功能,結(jié)合實(shí)例形式分析了AngularJS針對表單的校驗(yàn)、監(jiān)控等相關(guān)操作技巧,需要的朋友可以參考下2017-07-07
使用AngularJS編寫較為優(yōu)美的JavaScript代碼指南
這篇文章主要介紹了使用AngularJS編寫較為優(yōu)美的JavaScript代碼指南,包括控制器和封裝等進(jìn)階技巧上的編程建議,傾力推薦!需要的朋友可以參考下2015-06-06
Angular實(shí)現(xiàn)響應(yīng)式表單
本篇文章主要介紹了Angular實(shí)現(xiàn)響應(yīng)式表單,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08
Angular.js中ng-include用法及多標(biāo)簽頁面的實(shí)現(xiàn)方式詳解
這篇文章主要給大家介紹了在Angular.js中ng-include用法及多標(biāo)簽頁面的實(shí)現(xiàn)方式的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),相信對大家具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編一起來學(xué)習(xí)學(xué)習(xí)吧。2017-05-05
淺談angular.js中實(shí)現(xiàn)雙向綁定的方法$watch $digest $apply
Angular用戶都想知道數(shù)據(jù)綁定是怎么實(shí)現(xiàn)的。你可能會(huì)看到各種各樣的詞匯:$watch,$apply,$digest它們是如何工作的呢?這里我想回答這些問題,其實(shí)它們在官方的文檔里都已經(jīng)回答了,但是我還是想把它們結(jié)合在一起來講2015-10-10

