Helper module to provide some basic convenience methods
npm install imxquery
$ npm install imxquery
`
After this you can simply require imxQuery:
`javascript
var imxQuery = require('imxquery');
`
Accessing imxQuery
imxQuery down to the base, is a simple VanilaJS module. You can access it through several public methds:
$3
offsetTop will return you the top offset of a given node relative to the body
`javascript
imxQuery.offsetTop(htmlNode);
`
$3
offsetTop will return you the left offset of a given node relative to the body
`javascript
imxQuery.offsetLeft(htmlNode);
`
$3
scrollTo will scroll the window to a specific position.
`javascript
imxQuery.scrollTo(xPosition, yPosition, duration);
`
#### The params
* xPosition - target position on the x-axis
* yPosition - target position on the y-axis
* duration - amount of time it shall need, for the scroll to perform
#### Tip
In order to scroll to a specific node on the page, you can combine the offset methods with the scroll method:
`javascript
imxQuery.scrollTo(0, imxQuery.offsetTop(htmlNode), 100);
`
$3
The same as scrollTo, but scrolls inside an element.
`javascript
imxQuery.scrollElementTo(xPosition, yPosition, duration, targetNode);
`
* targetNode - the htmlNode that you want to scroll
$3
A handy small wrapper method to read out data attributes
`html
`
`javascript
imxQuery.accessDataset(document.getElementById('myTestArticle'), 'info_latitude');
`
$3
Extend an object with another object, adding missing fields
`javascript
var baseObject = {
title : 'title text',
text : 'a lot of text'
};
var configObject = {
lat : '54.765',
lng : '7.897'
};
imxQuery.extendObject(baseObject, configObject);
`
This will result in:
`javascript
var baseObject = {
title : 'title text',
text : 'a lot of text',
lat : '54.765',
lng : '7.897'
};
`
$3
Wait for the document to be loaded completly, to perform a callBack function.
`javascript
imxQuery.documentReady(function(){
alert('document is loaded');
});
``