GithubHelp home page GithubHelp logo

isabella232 / kissui.position Goto Github PK

View Code? Open in Web Editor NEW

This project forked from usablica/kissui.position

0.0 0.0 0.0 25 KB

Track element(s) on the page like a boss.

Home Page: http://usablica.github.io/kissui.position/

License: MIT License

JavaScript 92.36% HTML 7.64%

kissui.position's Introduction

kissui.position

Track element(s) on the page like a boss.

This library is a part of Kissui project.

Install

You can use NPM or Bower or download the package manually.

Getting Started

Using this libarary is as easy as adding data-kui-position attribute to your elements:

<p data-kui-position="in"></p>

and then bind an event listener:

kissuiPosition.on ('in', function (element) {
  console.log('yay!', element);
});

and to init the library, call this before </body>:

kissuiPosition.init();

That's it.

Events

Here is a list of available events:

  • in - when element is in the viewport
  • out - when element is not in the viewport
  • middle - center aligned element (vertically)
  • center - center aligned element (horizontally)
  • top - element at the top of the page
  • bottom - elemennt at the bottom of the page
  • left - element at the left side of the page
  • right - element at the right side of the page
  • partially - with one only works with out event, e.g. partially out and it means when the element is partially out of the element (e.g. half of the height or width)

Also, it is possible to use a compond of events together.

Example:

Element is in the viewport and center of the page:

<p data-kui-position="in center"></p>

Element is located in the center and middle of the page:

<p data-kui-position="in middle center"></p>

EventListener

It is possible to listen to events and catch them using following methods.

ID-based event

You can get the events of an element using its ID. Let's say you have:

<p id="paragraph" data-kui-position="in right">This element is tracking by Kissui.Position</p>

then you can get events using:

kissuiPosition.on('paragraph', function (element) {
  console.log('with id', element);
});

* event

If you want to get all events, simply bind a callback function to * event:

kissuiPosition.on('*', function (element, event) {
  console.log('*', element, event);
});

position event

Also, you can get all events using its unique data-kui-position attribute value. So, imagine you have:

<p id="paragraph" data-kui-position="in right">this element is tracking by kissui.position</p>

then you can listen to events from in right (with the same order):

kissuiPosition.on('in right', function (element) {
  console.log('single', element);
});

TODOs

  • The combination of out and other events are not completely implemented. now it works with top only, e.g. out top. we should implement other positions as well.
  • Unit testing

What to help? I have a look at the TODO list and send a PR, cheers.

Author

Afshin Mehrabani

License

MIT

kissui.position's People

Contributors

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