A Metal.js extension that provides static utilities for browser positioning.
- Install NPM, if you don't have it yet.
- Run
npm install metal-position
. The code will be available atnode_modules/metal-position
.
With the code already available, you can use Metal Position by just importing the desired module on your js file and calling what you wish on it. For example:
import position from 'node_modules/metal-position/src/position';
// You can now call any function from Metal's Position module.
position.getClientHeight();
Note that Metal Position is written in ES6 (a.k.a ECMAScript 2015), so you can also use ES6 on your code like we did on the example. Since ES6 isn't fully implemented on browsers yet though, either a polyfill or a build process is necessary before using Metal on a website. See the Metal.js documentation for more details.
There are few different utilities available:
Gets the client height of the specified node. Scroll height not included:
position.getClientHeight(document);
position.getClientHeight(window); // Viewport height, scroll height not included.
Gets the client width of the specified node. Scroll width not included:
position.getClientWidth(document);
position.getClientWidth(window); // Viewport width, scroll width not included.
Gets the height of the specified node. Scroll height is included.
position.getHeight(node);
Gets the width of the specified node. Scroll width is included.
position.getWidth(node);
Gets the size of an element and its position relative to the viewport. The returned value is a DOMRect object which is the union of the rectangles returned by getClientRects() for the element, i.e., the CSS border-boxes associated with the element.
position.getRegion(node); // {height:6583, width:1058, left:0, bottom:5305, right:1058, top:-1278}
Gets the scroll left position of the specified node.
position.getScrollLeft(node);
Gets the scroll top position of the specified node.
position.getScrollTop(node);
Tests if a region intersects with another.
position.intersectRegion(region1, region2);
Tests if a region is inside another.
position.insideRegion(region1, region2);
Tests if a region is inside viewport region.
position.insideViewport(region);
Computes the intersection region between two regions.
position.intersection(region1, region2);
Makes a region object. It's a writable version of DOMRect.
position.makeRegion(bottom, height, left, right, top, width);
Install Gulp:
[sudo] npm install -g gulp
Fetch local dependencies:
npm install
bower install
Build or watch files:
gulp build
gulp watch
Run or watch tests:
gulp test
gulp test:watch
For detailed changelog, see Releases.
BSD License © Liferay, Inc.