npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-masonry

v1.0.6

Published

Show items with different height in a grid of responsive columns. Works great with bootstrap.

Downloads

101

Readme

Simple Masonry

simple-masonry.js

Build Status

Show items with different heights in a grid of responsive columns. No position: absolute and so fully flexible in height and width of any item.

Check demo.

simple-masonry.js is written as es6. If you are not using a es6-compiler in your project then use simple-masonry-compiled.js!

simple-masonry works great with bootstrap (but you can use your own grid as well!). Wrap some columns in a container and fill them with items. It dosn't matter if you put them all in one column or preorder them. simple-masonry will order all items from each column in a zipper method as you can see in the following snippet.

<!-- wrap columns -->
<section class="masonry-box container">
    <!-- columns 1 -->
    <div class="masonry-column col-lg-3 col-md-4 col-sm-6 col-xs-12">
        <div class="item">
            <h3>item 1</h3>
        </div>
        <!-- item 2 is allready in the second masonry-column -->
        <!-- item 3 is allready in the third masonry-column -->
        <div class="item">
            <h3>item 4</h3>
        </div>
        <div class="item">
            <h3>item 5</h3>
        </div>
        <div class="item">
            <h3>item 6</h3>
        </div>
        <div class="item">
            <h3>item 7</h3>
        </div>
        <div class="item">
            <h3>item 8</h3>
        </div>
    </div>
    <!-- columns 2 -->
    <div class="masonry-column col-lg-3 col-md-4 col-sm-6">
        <div class="item">
            <h3>item 2</h3>             
        </div>
    </div>
    <!-- columns 3 -->
    <div class="masonry-column col-lg-3 col-md-4">
        <div class="item">
            <h3>item 3</h3>
        </div>
    </div>
    <!-- columns 4 -->
    <div class="masonry-column col-lg-3"></div>
</section>

Create columns and set the column width with bootstrap classes (or other grid system) like usual. !important: set 'col-[]-12' classes! Also if it seems to be senseless in normal use.

In default you can use the css-class masonry-box for the wrapping element and masonry-column for columns. Items don't need a extra class. Every element will be ordered if it's not just a pure text-node.

Get simple-masonry and include it in your project.

npm

$ npm install simple-masonry -S

bower

$ bower install simple-masonry

You can use your own classes for wrapping element and columns if you put them as parameter.

Usage

var simpleM = new SimpleMasonry();

Or with your own selector.

var simpleM = new SimpleMasonry({
    masonryBox: '.my-box-class',
    masonryColumn: '.my-column-class'
});

Then run it

// init all and order items
simpleM.init();

.append()

// add a node or an array of nodes at the end of all items
simpleM.append(node);
simpleM.append([node1, node2]);

.prepend()

// add a node or a array of nodes at the beginning of all items
simpleM.prepend(node);
simpleM.prepend([node1, node2]);

.get()

// get all items in an array
simpleM.get();
// get all items in an array of the column with this index
simpleM.get(index);

.each()

// iterate trough all items
simpleM.each(function (item, index) {
    // do stuff
});
// or to all items of a single column
simpleM.each(function (item, index) {
    // do stuff
}, columnIndex);

// tip: use native Array-iterator
simpleM.get().forEach(function (item, index) {
    // do stuff
});

.columnsLength()

simpleM.columnsLength();
// returns number of available columns

.on()

// register a eventListener
simpleM.on('append', function (item) {
    // do stuff
});
simpleM.on('prepend', function (item) {
    // do stuff
});
simpleM.on('order', function (items) {
    // do stuff
});

Demo and more information here.


Authors