Mondrian

Size
2,787 Kb
Views
26,312

How do I make an mondrian?

Hit spacebar or shake your phone to create a new composition, and drag blocks about to adjust.Made using Dave Desandro’s Packery and Draggibilly.. What is a mondrian? How do you make a mondrian? This script and codes were developed by Chrisarmstrong on 24 November 2022, Thursday.

Mondrian Previews

Mondrian - Script Codes HTML Codes

<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Mondrian</title> <script src="https://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script>
<meta name="viewport" content="width=device-width">
<meta name="apple-mobile-web-app-capable" content="yes"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="container">
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://packery.metafizzy.co/packery.pkgd.min.js'></script>
<script src='https://draggabilly.desandro.com/draggabilly.pkgd.min.js'></script>
<script src='https://raw.githubusercontent.com/alexgibson/shake.js/master/shake.js'></script> <script src="js/index.js"></script>
</body>
</html>

Mondrian - Script Codes CSS Codes

.item { width:48px; height:48px; background:white; display:block; cursor:move;
}
.item:hover { border:4px solid rgba(0,0,0,0.2); box-sizing:border-box;
}
#codepen-footer { display:none;
}
.item:nth-child(3){ background:#E50F05;
}
.item:nth-child(7){ background:#264D98;
}
.item:nth-child(9){ background:#F9DE45;
}
.w2 { width:116px;
}
.h2 { height:116px;
}
.h3 { height:184px;
}
.w3 { width:184px;
}
html { width:100%; height:100%; display:table;
}
body { width:100%; height:100%; background:black; margin:0; padding:0; vertical-align:middle; display:table-cell;
}
#container { width:320px; min-height:568px; max-height:100vh; overflow:hidden; outline:1px solid white; margin:auto;
}

Mondrian - Script Codes JS Codes

// init
setStage();
function setStage() { var $container = $('#container'); $container.packery( 'remove', $('.item') ); $container.packery({ itemSelector: '.item', gutter:20, columnWidth: 48, rowHeight: 48 }); var i=34; $('#container').html(''); for (i; i > -1; i--) { var item = document.createElement("div"); switch (Math.round(Math.random()*10)) { case 1: item.className="item w2"; i = i-1; break; case 2: item.className="item h2"; i = i-1; break; case 3: item.className="item h2 w2"; i = i-3; break; case 4: item.className="item h3"; i = i-2; break; case 5: item.className="item w3"; i = i-2; break; case 6: item.className="item w3 h3"; i = i-8; break; default: item.className="item"; } $('#container').append(item); $container.packery( 'appended', item ); if (i<=0) { $container.find('.item').each( function( i, itemElem ) { // make element draggable with Draggabilly var draggie = new Draggabilly( itemElem ); // bind Draggabilly events to Packery $container.packery( 'bindDraggabillyEvents', draggie ); }); } }
}
function layout() { $container.find('.item').each( function( i, itemElem ) { // make element draggable with Draggabilly var draggie = new Draggabilly( itemElem ); // bind Draggabilly events to Packery $container.packery( 'bindDraggabillyEvents', draggie ); });
}
window.addEventListener('shake', shakeEventDidOccur, false);
//function to call when shake occurs
function shakeEventDidOccur () { //put your own code here etc. onShake();
}
$('body').keyup(function(e){ if(e.keyCode == 32){ // user has pressed space onShake(); }
});
function onShake() { setStage();
}
Mondrian - Script Codes
Mondrian - Script Codes
Home Page Home
Developer Chrisarmstrong
Username chrisarmstrong
Uploaded November 24, 2022
Rating 4
Size 2,787 Kb
Views 26,312
Do you need developer help for Mondrian?

Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!

Chrisarmstrong (chrisarmstrong) Script Codes
Create amazing web content with AI!

Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!