Home > Web Front-end > JS Tutorial > body text

AngularJS implements drop-down scrolling loading method based on ngInfiniteScroll

高洛峰
Release: 2016-12-29 10:43:54
Original
1404 people have browsed it

The example in this article describes how AngularJS implements drop-down scrolling loading based on ngInfiniteScroll. Share it with everyone for your reference, the details are as follows:

1. On the basis of loading data in pages, how to achieve the effect of loading data in pages through rolling loading? On github, there is a good plug-in for AngularJS, address For: https://github.com/sroze/ngInfiniteScroll

2. Let’s look at the official document

(1) Usage example:


Copy after login

Explanation Each attribute (the meaning of the command)

①infinite-scroll - {expression} When scrolling to the bottom of the browser, the function or expression executed is usually in the form of a function.

②infinite-scroll-distance (optional) - {number} expression or number. If it is a number, it indicates how far the scroll bar is from the bottom of the browser, and the function in ① is executed. If this value is set to 2, for an element with a height of 1000px, when the distance between the bottom of the element and the bottom of the browser window is within 2000px pixels, the function in ① will be executed once without scrolling once. (This value defaults to 0, that is, when the element scrolls to the bottom of the element and reaches the bottom of the browser window (scroll area), the function in the scroll area is executed.

③infinite-scroll-disabled (optional) - {boolean} A Boolean value used to indicate whether the scrolling expression function can be executed. If the value is true, it means that the scrolling function cannot be executed. This attribute is usually used to pause or stop scrolling when we move the data during AJAX request. For scroll bars, you need to set this attribute to disable the execution of the scroll function.

④infinite-scroll-immediate-check (optional) - {boolean} A Boolean value used to mark the instruction when initializing the page. Whether to execute it once initially (even in this case, there is no initial scrolling), the default value is true, which means that the function inside will be executed once initially.

⑤infinite-scroll-listen-for-event (optional). ) - {string} An event. When this event is received, the scroll function will be re-executed and the scroll position will be repositioned. For example, when the element is modified, the scroll function will be re-executed.

(2) Local. The DEMO

official website gives an example of running locally and implementing rolling loading:

HTML code:

Copy after login

JS code:

var myApp = angular.module('myApp', ['infinite-scroll']);
myApp.controller('DemoController', function($scope) {
 $scope.images = [1, 2, 3, 4, 5, 6, 7, 8];
 $scope.loadMore = function() {
  var last = $scope.images[$scope.images.length - 1];
  for(var i = 1; i <= 8; i++) {
   $scope.images.push(last + i);
  }
 };
});
Copy after login

I hope this article will explain It will be helpful to everyone in AngularJS programming.

For more related articles on AngularJS’s method of implementing drop-down scrolling based on ngInfiniteScroll, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!