GithubHelp home page GithubHelp logo

caktoy / lokasi Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 76 KB

Get coordinate of element (top, left, right, bottom) of has parent (parent node or parent element)

License: MIT License

HTML 55.54% JavaScript 44.46%

lokasi's Introduction

Lokasi

Sample of image preview

Lokasi is simple library to get() and set() position of element with structure "Object Pattern" and compatible with AMD or Common JS module. Lokasi can use without dependency like jQuery etc. and this library will be return position of object / element with initialize on class like <div class="target"></div> and will be return parent of element too.

Note : Don't forget to set parent position with relative and result of position will be affect for their parent

Example

Just clone / download this repository and try on browser or see index.html file.

How to use

Lokasi just have two method inner class Lokasi :

1. Method .get()

Use method .get() to get position and parent of object / element, this method will be return object like this :

	
	Lokasi.get('.target-3');

	/* result
		{
			target: <div.target-3>,
			parent: <div.wrapper-1>, 
			left: 135,
			top: 18,
			right: 425,
			bottom: 124
		}
	*/

2. Method .set()

Use method .set() to set position of object / element, this method have 3 parameters to use (target, offset left, offset right) :

	
	Lokasi.set('.target-5', 20, 10);

If you want to get callback after action, you can use callback like this :

	
	Lokasi.set('.target-5', 20, 10, function(res) {
		console.log(res);
	});

	/* result
		{
			target: <div.target-5>,
			parent: <div.wrapper-2>, 
			left: 20,
			top: 10,
			right: 540,
			bottom: 30
		}
	*/

License

Don't worry of license, just use it when you need. Contact me if you have problem for this library ([email protected]) or @muhibbudins (LinkedIn and Github). Thanks for watching

lokasi's People

Contributors

muhibbudins avatar

Watchers

 avatar  avatar

Forkers

alexanderps3393

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.