JSFiddle - React, Tailwind, and code Playground

by rich_harris

HTML

<script src="http://cdnjs.cloudflare.com/ajax/libs/masonry/3.2.2/masonry.pkgd.min.js"></script>
<main></main>

<script id='template' type='text/ractive'>
    {{#each items :i}}
        <div style='width: {{width}}px;
                    height: {{height}}px;
                    background-color: {{colour}};'>{{i}}</div>
    {{/each}}
</script>

CSS

body {
    font-family: 'Helvetica Neue', arial, sans-serif;
    font-weight: 200;
    color: #353535;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 200;
}

.error {
    color: #d00;
    font-family: monospace;
}

JavaScript

var ractive = new Ractive({
    el: 'main',
    template: '#template',
    data: {
        items: getItems( 10 )
    }
});

var masonry = new Masonry( ractive.el );

setInterval( function () {
    var index = ~~( Math.random() * ractive.get( 'items.length' ) );
    
    ractive.splice( i, 0, getItem() );
    masonry.layout();
}

function getItems ( i ) {
    var items = [];
    while ( i-- ) {
        items.push( getItem() );
    }           
    return items;
}

function getItem () {
    return {
        width: 10 + rn( 20 ),
        height: 10 + rn( 20 ),
        colour: 'rgb(' + [ rn(255), rn(255), rn(255) ].join( ',' ) + ')'
    };
}