Giter Site home page Giter Site logo

metal-position's Introduction

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.

metal-position's People

Contributors

eduardolundgren avatar jbalsas avatar mairatma avatar zenorocha avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

metal-position's Issues

Add feature to allow force the preferred alignment position

Nowadays, metal-position always try auto-align the element to fit the viewport. But a developer might prefer don't follow this behaviour.

We can achieve this by adding a property autoAlignment, that is true by default. In case the developer sets it to false we skip the autoAlignment.

Add ability to specify the size of the space between the element and alignElement

It would be useful to be able to specify the size of the space you would like between the element and alignElement for the Align.getAlignRegion method.

I think this could be done by adding a parameter that accepts a number value to the Align.getAlignRegion method for the spacing size and then add or subtract the value of the spacing parameter to the values in each of the switch statements.

The parameter will probably need to be added to other methods that use Align.getAlignRegion like Align.align as well.

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.