Code Monkey home page Code Monkey logo

angular-masonry's Introduction

AngularJS Masonry Directive Build StatusDependency Status Code Climate

Homepage

An AngularJS 1 directive to work with David Desandro's Masonry.

Usage

  1. Install via either bower or npm:

    1. bower install --save angular-masonry
    2. npm install --save angular-masonry
  2. Add wu.masonry to your application's module dependencies.

  3. Include dependencies in your HTML.

    <script src="bower_components/jquery/dist/jquery.js"></script>
    <script src="bower_components/jquery-bridget/jquery-bridget.js"></script>
    <script src="bower_components/ev-emitter/ev-emitter.js"></script>
    <script src="bower_components/desandro-matches-selector/matches-selector.js"></script>
    <script src="bower_components/fizzy-ui-utils/utils.js"></script>
    <script src="bower_components/get-size/get-size.js"></script>
    <script src="bower_components/outlayer/item.js"></script>
    <script src="bower_components/outlayer/outlayer.js"></script>
    <script src="bower_components/masonry/masonry.js"></script>
    <script src="bower_components/imagesloaded/imagesloaded.js"></script>
    <script src="bower_components/angular/angular.js"></script>
    <script src="bower_components/angular-masonry/angular-masonry.js"></script>
  4. Use the masonry directive.

Example

See the homepage for a live example.

<div masonry>
    <div class="masonry-brick" ng-repeat="brick in bricks">
        <img ng-src="{{ brick.src }}" alt="A masonry brick">
    </div>
</div>

You have to include the masonry attribute on the element holding the bricks. The bricks are registered at the directive through the masonry-brick CSS classname.

The directive uses imagesloaded to determine when all images within the masonry-brick have been loaded and adds the loaded CSS class to the element, so you can add custom styles and prevent ghosting effects.

Attributes

item-selector

(Default: .masonry-brick)

You can specify a different item selector through the item-selector attribute. You still need to use masonry-brick either as class name or element attribute on sub-elements in order to register it to the directive.

Example:

<masonry item-selector=".mybrick">
    <div masonry-brick class="mybrick">Unicorns</div>
    <div masonry-brick class="mybrick">Sparkles</div>
</masonry>

column-width

The column-width attribute allows you to override the the width of a column of a horizontal grid. If not set, Masonry will use the outer width of the first element.

Example:

<masonry column-width="200">
    <div class="masonry-brick">This will be 200px wide max.</div>
</masonry>

preserve-order

The preserve-order attributes disables the imagesLoaded logic and will instead display bricks by the order in the DOM instead of by the time they are loaded. Be aware that this can lead to visual glitches if the size of the elements isn't set at the time they are inserted.

Example:

<masonry preserve-order>
    <div class="masonry-brick"><img src="..." alt="Will always be shown 1st"></div>
    <div class="masonry-brick"><img src="..." alt="Will always be shown 2nd"></div>
</masonry>

load-images

This attribute defaults to true and allows to disable the use of imagesLoaded altogether, so you don't have to include the dependency if your masonry layout doesn't actually make use of images.

Example:

<masonry load-images="false">
    <div class="masonry-brick"><p>Only text.</p></div>
    <div class="masonry-brick"><p>And nothing but text.</p></div>
</masonry>

reload-on-show

The reload-on-show attribute triggers a reload when the masonry element (or an ancestor element) is shown after being hidden, useful when using ng-show or ng-hide. Without this if the viewport is resized while the masonry element is hidden it may not render properly when shown again.

Example:

<masonry reload-on-show ng-show="showList">
    <div class="masonry-brick">...</div>
    <div class="masonry-brick">...</div>
</masonry>

When showList changes from falsey to truthy ctrl.reload will be called.

reload-on-resize

The reload-on-resize attribute triggers a reload when the masonry element changes its width, useful when only the parent element is resized (and not the window) and you want the elements to be rearranged. Without this if the parent is resized then some blank space may be left on the sides.

Example:

<masonry reload-on-resize>
    <div class="masonry-brick">...</div>
    <div class="masonry-brick">...</div>
</masonry>

masonry-options

You can provide additional options as expression either as masonry or masonry-options attribute.

Example:

<masonry masonry-options="{ transitionDuration: '0.4s' }">
</masonry>

Equivalent to:

<div masonry="{ transitionDuration: '0.4s' }">
</div>

prepend

Bricks are appended by default. This behavior can be specified for each brick by providing the prepend attribute.

Example:

<div masonry>
    <div class="masonry-brick" prepend="isPrepended()">...</div>
</div>

Credits

The directive is based on a StackOverflow question answered by James Sharp.

Contributing

Please refer to CONTRIBUTING.md before opening issues or pull requests.

License

MIT

Bitdeli Badge

angular-masonry's People

Contributors

passy avatar jodytate avatar delapouite avatar jonnybgod avatar tomersimis avatar bitdeli-chef avatar foxyblocks avatar desandro avatar t3chnoboy avatar jeffreyatw avatar jonanh avatar kkolstad avatar evermax avatar omribernstein avatar 0x-r4bbit avatar phuwanart avatar nicolai86 avatar tiddolangerak avatar vrouet avatar vtertre avatar dremonkey avatar homerjam avatar danielepiccone avatar philipkaare avatar

Watchers

James Cloos avatar lilili 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.