caktoy / lokasi

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 (muhibbudinsuretno1@gmail.com) or @muhibbudins (LinkedIn and Github). Thanks for watching

About

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

License:MIT License


Languages

Language:HTML 55.5%Language:JavaScript 44.5%