Skip to content
This repository has been archived by the owner on Feb 20, 2018. It is now read-only.
/ metal-position Public archive

A Metal.js extension that provides static utilities for browser positioning

License

Notifications You must be signed in to change notification settings

deprecate/metal-position

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Metal.js Position Dependency Status

Sauce Test Status

A Metal.js extension that provides static utilities for browser positioning.

Install

  1. Install NPM, if you don't have it yet.
  2. Run npm install metal-position. The code will be available at node_modules/metal-position.

Getting Started

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:

position.getClientHeight(node)

Gets the client height of the specified node. Scroll height not included:

position.getClientHeight(document);
position.getClientHeight(window); // Viewport height, scroll height not included.

position.getClientWidth(node)

Gets the client width of the specified node. Scroll width not included:

position.getClientWidth(document);
position.getClientWidth(window); // Viewport width, scroll width not included.

position.getHeight(node)

Gets the height of the specified node. Scroll height is included.

position.getHeight(node);

position.getWidth(node)

Gets the width of the specified node. Scroll width is included.

position.getWidth(node);

position.getRegion(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}

position.getScrollLeft(node)

Gets the scroll left position of the specified node.

position.getScrollLeft(node);

position.getScrollTop(node)

Gets the scroll top position of the specified node.

position.getScrollTop(node);

position.intersectRegion(region1, region2)

Tests if a region intersects with another.

position.intersectRegion(region1, region2);

position.insideRegion(region1, region2)

Tests if a region is inside another.

position.insideRegion(region1, region2);

position.insideViewport(region)

Tests if a region is inside viewport region.

position.insideViewport(region);

position.intersection(region1, region2)

Computes the intersection region between two regions.

position.intersection(region1, region2);

position.makeRegion(bottom, height, left, right, top, width)

Makes a region object. It's a writable version of DOMRect.

position.makeRegion(bottom, height, left, right, top, width);

Development

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

History

For detailed changelog, see Releases.

License

BSD License © Liferay, Inc.

About

A Metal.js extension that provides static utilities for browser positioning

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •