Giter Site home page Giter Site logo

islamcodehood / insideviewport.js Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 882 KB

An ultra light weight library that detects if an element is in viewport and lets you do some action to it.

License: MIT License

JavaScript 25.58% HTML 40.47% CSS 33.94%
javascript dom library inside viewport insideviewport

insideviewport.js's Introduction

insideViewport.js

An ultra light weight library that detects if an element is in viewport and lets you do some action to it.

Contents:

Description

  • An ultra light weight library built with vanilla javascript.
  • It enables you to detect if an element is in viewport.
  • It enables you to do whatever you want with the element in viewport.

Why use it?

  1. An ultra light weight (JUST 2KB).
  2. Written in pure vanilla javascript.
  3. Compatible with all browsers.
  4. Compatible with even old browsers, not only modern ones.
  5. No special setup or npm package install needed. Just copy and paste less than 30 lines of code at the top of your JS file.

Tutorial

Setup:

  1. Copy code in insideViewport.js file.
  2. Paste it in your JS file.

Use:

insideViewport({
 classesNames: ['example1', 'example2'],//An array of strings of class name(s).
 position: 0.5,//Optional. It controls where will be the element in the viewport area when the action done on it.
 action(elements) {
   myFunction(elements) //The action you want to do on the element.
 }
},
{ //more objects(arguments).
 classesNames: ['example3', 'example4'],
 action(elements) {
   myOtherFunction(elements) 
 }
})
  • You need to call insideViewport() with an object or any number of objects each one consists of three or two properties.
  • First property: classesNames which is an array of strings of class names of elements you want to detect.
  • Second property(optional): position which is a number value from 0 to less than 1. It controls where will be the element in the viewport area when the action done on it. As the number get bigger the element would be in higher position inside the viewport when the action done. For example, if the value was 0.5, the element would be in the middle of the viewport height when the function is called.
  • Third property: action(elements) which is a function to do some action on the element when in viewport.
  • You can use as many objects (arguments) as you need. Each one is intended to do the same action (same function) on one or multiple elements.

Contribute

  • This is an open source project. You can contribute, or report bugs.

License

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.