• Stars
    star
    480
  • Rank 88,292 (Top 2 %)
  • Language
    HTML
  • Created over 8 years ago
  • Updated about 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight masonry layout

Colcade

Lightweight masonry layout

Colcade vs. Masonry

Masonry is great, but it has grown big as it has grown older. Colcade is designed to be small & fast. I recommend using Colcade over Masonry, but read over this feature comparison.

Same features

  • Masonry grid layout
  • Works as a jQuery plugin or with vanilla JS
  • Initialize in HTML

Better features

  • Much smaller. 1/8 the size of Masonry
  • Better fluid/responsive layout, using native browser positioning
  • One file, no dependencies, no package dist built file
  • Does not require imagesLoaded when using images

Worse features

  • No multi-column-spanning items
OK                |  No
####  ####  ####  |  ##########  ####
####  ####  ####  |  ##########  ####
      ####        |
####        ####  |  ####  ##########
####  ####  ####  |  ####  ##########
####  ####  ####  |  ####
      ####        |

Install

Download: colcade.js

CDN:

<script src="https://unpkg.com/colcade@0/colcade.js"></script>

npm: npm install colcade

Bower: bower install colcade

Demos

Usage

Colcade works by moving item elements into column elements.

HTML

<div class="grid">
  <!-- columns -->
  <div class="grid-col grid-col--1"></div>
  <div class="grid-col grid-col--2"></div>
  <div class="grid-col grid-col--3"></div>
  <div class="grid-col grid-col--4"></div>
  <!-- items -->
  <div class="grid-item">...</div>
  <div class="grid-item">...</div>
  <div class="grid-item">...</div>
  ...
</div>

CSS

Sizing of the columns is handled by your own CSS. Change the number of columns by hiding or showing them.

/* Using floats */
.grid-col {
  float: left;
  width: 50%;
}

/* 2 columns by default, hide columns 2 & 3 */
.grid-col--2, .grid-col--3 { display: none }

/* 3 columns at medium size */
@media ( min-width: 768px ) {
  .grid-col { width: 33.333%; }
  .grid-col--2 { display: block; } /* show column 2 */
}

/* 4 columns at large size */
@media ( min-width: 1080px ) {
  .grid-col { width: 25%; }
  .grid-col--3 { display: block; } /* show column 3 */
}

Edit float demo on CodePen

/* with flexbox */
.grid {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
}

.grid-col {
  -webkit-box-flex: 1;
  -webkit-flex-grow: 1;
  -ms-flex-positive: 1;
  flex-grow: 1;
}

/* 2 columns by default, hide columns 2 & 3 */
.grid-col--2, .grid-col--3 { display: none }

/* 3 columns at medium size */
@media ( min-width: 768px ) {
  .grid-col--2 { display: block; } /* show column 2 */
}

/* 4 columns at large size */
@media ( min-width: 1080px ) {
  .grid-col--3 { display: block; } /* show column 3 */
}

Edit flexbox demo on CodePen

Initialize Colcade

Set selectors for column and item elements in the options.

With jQuery. Edit jQuery demo on CodePen

$('.grid').colcade({
  columns: '.grid-col',
  items: '.grid-item'
})

With vanilla JS. Edit vanilla JS demo on CodePen

// element as first argument
var grid = document.querySelector('.grid');
var colc = new Colcade( grid, {
  columns: '.grid-col',
  items: '.grid-item'
});

// selector string as first argument
var colc = new Colcade( '.grid', {
  columns: '.grid-col',
  items: '.grid-item'
});

With HTML. Edit HTML demo on CodePen

<div class="grid" data-colcade="columns: .grid-col, items: .grid-item">
  ...
</div>

Methods

append

Add items to end of layout.

// jQuery
$grid.colcade( 'append', items )
// vanilla JS
colc.append( items )

prepend

Add items to beginning of layout.

// jQuery
$grid.colcade( 'prepend', items )
// vanilla JS
colc.prepend( items )

destroy

Remove Colcade behavior completely.

// jQuery
$grid.colcade('destroy')
// vanilla JS
colc.destroy()

By David DeSandro

MIT License. Have at it.

More Repositories

1

masonry

๐Ÿฉ Cascading grid layout plugin
HTML
16,189
star
2

imagesloaded

๐Ÿ“ท JavaScript is all like "You images done yet or what?"
JavaScript
8,860
star
3

draggabilly

๐Ÿ‘‡ Make that shiz draggable
JavaScript
3,839
star
4

3dtransforms

๐Ÿ“ฆ Introduction to CSS 3D transforms
CSS
1,003
star
5

classie

๐ŸŽฉ class helper functions
JavaScript
871
star
6

close-pixelate

Pixelate an image with <canvas> a la Chuck Close
JavaScript
725
star
7

vanilla-masonry

[deprecated] Masonry layouts without any frameworks
JavaScript
329
star
8

practical-ui-physics

Learn basic physics for UI
JavaScript
323
star
9

breathing-halftone

Images go whoa with lots of floaty dots
JavaScript
254
star
10

windex

Pretty up your localhost. No more 1996 jank.
CSS
183
star
11

get-size

๐Ÿ“ Measure elements
JavaScript
176
star
12

arpeggiator

Web audio arpeggiator
JavaScript
176
star
13

CSS3.tmbundle

TextMate bundle for new CSS3 properties. Includes vendor specific properties and HTML5 elements
108
star
14

jquery-bridget

๐ŸŒ‰ bridget makes jQuery plugins
JavaScript
108
star
15

zui-site-riot

Tutorial for zoom-scrolling on 2011.beercamp.com
JavaScript
54
star
16

eventie

event binding helper
JavaScript
54
star
17

doc-ready

lets get this party started... on document ready
JavaScript
50
star
18

sticky-titles

iOS/Android-like fixied titles that scroll sorta
JavaScript
33
star
19

jumbyl

Post to Tumblr from the command line
JavaScript
31
star
20

neo-vision

Chrome extension that syntax-highlights source code files with customizable themes
JavaScript
30
star
21

matches-selector

๐Ÿ‘— matchesSelector helper
JavaScript
29
star
22

dotfiles

Personalized settings for Terminal, Git, TextMate, etc.
Shell
20
star
23

v3.desandro.com

All about me! In orange!
JavaScript
20
star
24

masonry-docs

๐Ÿ“ Documentation for Masonry
Handlebars
20
star
25

textmate-bundles

My modifications to TextMate's bundles
HTML
19
star
26

v2.desandro.com

My personal site. Runs on Stacey CMS
PHP
18
star
27

curtis-css-typeface

type made with CSS shapes
CSS
18
star
28

transitn

JS utility class for CSS transitions
JavaScript
17
star
29

get-style-property

quick & dirty CSS property testing
JavaScript
16
star
30

welovemariokart

JavaScript
14
star
31

dropshado.ws

๐Ÿ‘ป blog about front-end development minutiae
JavaScript
13
star
32

smallblog

๐Ÿญ I don't know how to put this in words but this is me trying
CSS
9
star
33

ani-halftone

Animated halftones
JavaScript
9
star
34

typekit-table

Sort and filter high-quality fonts from Typekit
JavaScript
8
star
35

requirejs-bower-homework

Help me figure out this RequireJS business
JavaScript
7
star
36

jtetypes

Try out fonts by James T. Edmondson
JavaScript
7
star
37

lists

๐Ÿ“œ of lists
7
star
38

motion-emotion

Presentation on CSS transitions and transforms
6
star
39

demo

Demos, tests, and misfit fun things
JavaScript
6
star
40

organize-bower-sources

Get Bower dependency source files, in order, listed by file extension.
JavaScript
5
star
41

nclud-v3-talk

Presentation outline for talk about nclud.com v3
JavaScript
5
star
42

issues-agreement

Help me dev you
5
star
43

touchy-feely-dev

Outline for presentation at Future Insights Live 2012
CSS
4
star
44

mcgilldesandro.com

I'm getting hitched. This is the website.
JavaScript
4
star
45

dotvim

Vim config
Vim Script
4
star
46

make-julesmarie-cry

A sadistic bookmarklet for "Click here" links
JavaScript
4
star
47

mobile-safari-machete

"Mobile Safari: Bring your machete" presentation from Front Trends 2012
JavaScript
4
star
48

prefs

Personal preferences
3
star
49

blahble

A boring Tumblr theme
HTML
3
star
50

concatminify.com

Help newbie devs learn concat & minify
CSS
3
star
51

open-source-aint-free

Talk for Valio Con 2012
JavaScript
3
star
52

bower-introduction

Notes for presentation
2
star
53

masonry-v2-3-shim

Maintain backwards compatibility using Masonry v3 with code for Masonry v2.
JavaScript
2
star
54

v4.desandro.com

Personal site
Handlebars
1
star
55

button-group

JavaScript
1
star