Giter Club home page Giter Club logo

in-vp's Introduction

In VP Build Status

Check if elements are fully or partially visible in the viewport

Installation

npm install in-vp

Usage

const inVp = require('in-vp');

const element = document.querySelector('.foo');
const { fully, partially, edges } = inVp(element);

API

inVp(element, [treshold])

Arguments

  • element (HTMLElement)
    The element, that will be tested.
    inVp(document.querySelector('.foo'));
  • treshold (Object)
    Shift the viewport boundaries to change the point where the element is considered in or out of the viewport. Positive values move the boundary inside the viewport, negative outside. This can come in handy if want to take fixed elements like a navigation into account. Currently only pixel values are supported.
    const element = document.querySelector('.foo');
    inVp(element, { top: 100 });

Return value

inVp() returns an object, that uses the following signature:

  • fully (boolean):
    True if the whole element is visible
  • partially (boolean):
    True if only a part of the element is visible
  • edges (object):
    Contains visibility information for all four edges of the element. Each edge can have three different states:
    • fully (string): The whole edge is visible
    • partially (string): Only a part of the edge is visible
    • false (boolean): The edge is completely invisible
{
  fully: boolean,
  partially: boolean,
  edges: {
    top:    'fully' |  'partially' | false,
    right:  'fully' |  'partially' | false,
    bottom: 'fully' |  'partially' | false,
    left:   'fully' |  'partially' | false
  }
}

License

MIT © Henning Pohlmeyer

in-vp's People

Contributors

dependabot[bot] avatar hpohlmeyer avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

in-vp's Issues

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.