Git Product home page Git Product logo

buoy.js's Introduction

buoy.js

buoy.js is a small utility script which helps the developer quickly vertically align an element to a container. Global and AMD are both supported.

Demos

http://codepen.io/Jshthornton/pen/aAdCH

Dependencies

  • jQuery

Usage

buoy.align({
	prop: 'margin', // The CSS method in which to use to position (margin 'margin-top' / top / padding 'padding-top'/ transform)
	$el: $('.inner'), // The element to vertically align
	$container: $('.container'), // The element to align to
	position: 50, // Percentage of the position. Example: 50 = 50%, thus $el is center aligned
	elFn: 'height', // The jQuery function to use to calculate height (height, innerHeight, outerHeight *False)
	containerFn: 'height' // The jQuery function to use to calculate height (height, innerHeight, outerHeight *False)
});

This is of course all of the options. However most of these options have a default value, allowing for a minimal setup such as:

buoy.align({
	$el: $('.inner'),
	$container: $('.container')
});

If you are experiencing the issue whereby the parent element is pushed down due to the margin then see this issue: http://stackoverflow.com/questions/2680478/margin-top-push-outer-div-down

The $el and $container are synchronised so that if the $el and $container contain more than 1 element then the alignment will occur on each $el with the corresponding $container. For example, if $el contains 3 elements, and $container contains 2 elements, then the first element in $el will align to the first element in $container and the second with the second. However the third in $el is ignored as it does not have a partner.

Images

buoy automatically manages image dimensions so that they are calculated after it has loaded to ensure that the correct dimensions are used.

buoy.js's People

Contributors

jshthornton avatar

Stargazers

Bili Xu avatar Fernando Toffolo avatar Uros Trebec avatar Stephen Walcher avatar Paul Brown avatar Shant Parseghian avatar  avatar  avatar  avatar

Watchers

 avatar

buoy.js's Issues

Add offset limit

Allow the developer to set what the limit is. At the moment it is hardcoded at 0. By inputting false there should be no limit, and defaults to 0.

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.