Coder Social home page Coder Social logo

paytvgo / angular-inview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thenikso/angular-inview

0.0 2.0 0.0 824 KB

AngularJS directive to check if a DOM element is in the browser viewport.

Home Page: http://thenikso.github.io/angular-inview/

License: MIT License

CoffeeScript 64.37% HTML 29.31% JavaScript 6.33%

angular-inview's Introduction

InView Directive for AngularJS

A directive to evaluate an expression if a DOM element is or not in the current visible browser viewport.

The directive is inspired by the jQuery.inview plugin. However this implementation has no dependency on jQuery.

Installation

To install using Bower:

bower install angular-inview

Setup

In your document include this scripts:

<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/angular-inview/angular-inview.js"></script>

In your AngularJS app, you'll need to import the angular-inview module:

angular.module('myModule', ['angular-inview']);

Usage

This module will define two directives: in-view and in-view-container.

InView

<any in-view="{expression using $inview}" in-view-options="{object}"></any>

The in-view attribute must contain a valid AngularJS expression to work. When the DOM element enter or exits the viewport, the expression will be evaluated. To actually check if the element is in view, the following data is available in the expression:

  • $inview is a boolean value indicating if the DOM element is in view. If using this directive for infinite scrolling, you may want to use this like <any in-view="$inview&&myLoadingFunction()"></any>.
  • $inviewpart is undefined or a string either top, bottom, both or neither indicating which part of the DOM element is visible.
  • $event is the DOM event that triggered the check; the DOM element that changed its visibility status is passed as $event.inViewTarget (To use the old $element variable use version 1.3.x).

An additional attribute in-view-options can be speficied with an object value containing:

  • offset: a number indicating how much to move down (or up if negative) the top position of the element for the purpose of inview testing;
  • offsetTop and offsetBottom: two numbers representing the top and bottom offset respectively; this may virtually change the height of the element for inview testing;
  • debounce: a number indicating a millisecond value of debounce which will delay firing the in-view event until that number of millisecond is passed without a scrolling event happening.

InViewContainer

Use in-view-container when you have a scollable container that contains in-view elements. When an in-view element is inside such container, it will properly trigger callbacks when the container scrolls as well as when the window scrolls.

<div style="height: 150px; overflow-y: scroll; position: fixed;" in-view-container>
	<div style="height:300px" in-view="{expression using $inview}"></li>
</div>

How to contribute

  1. Fork the repository and clone it to your machine
  2. Modify angular-inview.coffee and compile it with coffee -cw angular-inview.coffee (make sure that coffeescript is installed globally)
  3. Run bower install, npm install (make sure that nodejs, npm and bower are installed globally)
  4. Run tests by issuing: karma start (make sure, that karma-cli is installed globally)
  5. Commit your changes and create a PR

License

MIT

angular-inview's People

Contributors

ehsan89 avatar eknuth avatar pmanijak avatar thenikso avatar wli avatar

Watchers

 avatar  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.