Code Monkey home page Code Monkey logo

angular-infinite-scroll's Introduction

angular-infinite-scroll

super minimal infinite scroll library for angularJS ๐Ÿ“

only 600 bytes minified - used in production ๐ŸŽ†

So, after using the directive on a scrollable element, you need 1 thing to make this work: A function that gets more of what you're loading, and can set the loading and endOfList variables to false when applicable. This module comes with a rudimentary way to detect a mobile device, so feel free to use your own and pass it to the scrollMobile attribute. Depending on the size of your container, you can play around with scrollOfset and scrollShOffset (scrollHeightOffset) to make it smoother, but the defaults work well for small - medium containers.

Plunker Demo

Install

npm install angular-infinite-scroll

Usage

angular
  .module('myApp', ['angular-infinite-scroll'])
  .controller('myController', ['$scope', function($scope) {
    this.fooBars = (new Array(10)).fill("fooBar");
    console.log(this);
    this.makeMoreFooBars = () => {
      this.fooBars = this.fooBars.concat((new Array(10)).fill("fooBar"));
    }
    this.loadMoreFooBars = () => {
      console.log("Loading additional foobars!");
      this.makeMoreFooBars();
      $scope.scrollLoading = false;
      if (this.fooBars.length >= 500) {
        this.endOfList = true;
        console.log("End of list reached!");
      }
    }
     }]);
<body ng-app="myApp">
  <div ng-controller="myController as vm">
    <div al-infinite-scroll="vm.loadMoreFooBars()" scroll-offset="200" scroll-unbind="vm.endOfList">
        <ul>
            <li ng-repeat="foobar in vm.foobars">{{ foobar }}</li>
        </ul>
    </div>
</body>

Full options

<div al-infinite-scroll="vm.loadMoreFooBars()" scroll-offset="5" scroll-unbind="vm.endOfList" scroll-mobile="someMobileDetectionFn()" scroll-sh-offset="200"></div>

Development

npm install
npm run dev

Build

npm run build

angular-infinite-scroll's People

Contributors

aaronlifton avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.