Giter Club home page Giter Club logo

shmack.js's Introduction

Shmack.js

A jquery plugin to stack items into fluid columns, creating a grid layout similar to Pinterest.

Here's an example

Play with the code

Why Another Pinterest Clone?

There are already several plugins that do what shmack does. The only problem is that they use fixed calculated positioning, which results in bloat, possible rendering/paint issues, and isn't good for responsive layouts.

Shmack is a lighweight, responsive solution that stacks elements into columns, as apposed to using fixed calculations to position them.

How it Works

Shmack is quite simple. It takes a bunch of element blocks and wraps them in divs that act as columns. Each element is added to the column with the shortest height (this can be changed through settings). From that point on, you can style the blocks to look however you'd like.

How to Use

Add Markup

Create markup that includes a container with children:

<article id="shmack-it">
    <section class="block">
        <img class="pic" src="http://placecage.com/350/250">
        <h3>Block 1</h3>
    </section>
    <section class="block">
        <img class="pic" src="http://placecage.com/350/180">
        <h3>Block 2</h3>
    </section>
    <section class="block">
        <img class="pic" src="http://placecage.com/350/280">
        <h3>Block 3</h3>
    </section>
    <section class="block">
        <img class="pic" src="http://placecage.com/350/350">
        <h3>Block 4</h3>
    </section>
    <section class="block">
        <img class="pic" src="http://placecage.com/350/120">
        <h3>Block 5</h3>
    </section>
</article>

Note: By default, shmack is looking for the selector ".block"

Add the Plugin

Include jQuery and shmack.js at the bottom of your page:

<script type="text/javascript" src="path/to/jquery.js"></script>
<script type="text/javascript" src="path/to/jquery.shmack.min.js"></script>

Initialize the Plugin

Initialize the plugin on load:

$(document).ready(function(){
 	$('#shmack-it').shmack();
});

Add Some Styling

You can customize the CSS anyway you'd like. This is the minimum styling needed:

.block{
    /* Fallback for no js */
    width:33.333%;
    float:left;
}
    .shmack-column .block{
        width:auto;
        float:none;
    }

/* If not already added to CSS */
.clearfix:before,
.clearfix:after {
    content: "";
    display: table;
} 
.clearfix:after {
    clear: both;
}
.clearfix {
    zoom: 1; /* For IE 6/7 (trigger hasLayout) */
}

Note: The columns use the class "shmack-column"

Options

These are the options (and their defaults) that you can pass to shmack:

$('#shmack-it').shmack({
	blockSelector: '.block',	//String - Selector for elements to be sorted into columns
	columns: 3,				//Integer - Number of columns to stack
	loadImages: true,		//Boolean - Load images before stacking (important for calculating heights)
	setImageHeight: false,	//Boolean - Height of images is set using data-height (used for faster load times)
	onBlockLoad: false,		//Function - Callback after each block loads
	complete: false			//Function - Callback on complete
});

Similar Plugins

shmack.js's People

Contributors

mattdrose avatar

Stargazers

Blessan Mathew avatar Jonathan Barratt avatar Ian Walter avatar

Watchers

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