Git Product home page Git Product logo

alignment-class's Introduction

Alignment Class

This library can be used to dynamically ensure all child elements of a given CSS selector are assinged a class according to their position relative to their parent. On page-load the elements' positions are measured, elements nearest the left edge of thier parent get the class "alignment-left", elements nearest the right edge of their parent get the class "alingment-right", and if a tolerance value is provided elements further than the tolerance value from either edge get the class "alignment-center". On a window resize (or orientation change on mobile) the positions are measured again and the classes reset to accomodate any shift in layout caused by the change in window size.

Additional triggers can be added via LayoutQueue.

Installation

Install via npm or yarn.

npm install alignment-class

OR

yarn add alignment-class

Then require this module within your javascript:

var AlignmentClass = require('alignment-class');

Basic Use

The methods of AlignmentClass all use standard CSS selectors, (e.g. 'p', '.class', '#id'). To align the children of a element or set of elements, pass the selector to init():

AlignmentClass.init(selector);

A tolerance value in pixels can be added as a second parameter to set any child elements a class of alignment-center if they are further than the given pixel value from either side. Without a tolerance value, all children will be text-aligned either right or left.

AlignmentClass.init(selector, tolerance);

A third boolean parameter can be added to reverse the orientation, and align elements to the center rather than the sides. This parameter will default to false.

var reverse = true;
AlignmentClass.init(selector, tolerance, reverse);

A condition passed as a function can be added as a fourth parameter, allowing for a conditional applicaiton of the alignment.

var condition = function () { return false }
AlignmentClass.init(selector, tolerance, reverse, condition);

Advanced use

To manually unset alignment class of an elements children use unset():

AlignmentClass.unset(selector);

To manually set the alignment class of an elements children use 'set()';

AlignmentClass.set(selector);

To add additional triggers for the execution of the queue see the documentation for LayoutQueue;

alignment-class's People

Contributors

davejtoews avatar dependabot[bot] avatar

Watchers

 avatar

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.