JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<h1>Packery - centered</h1>
<p>This feature will only work with fixed-width columns.</p>
<div class="packery">
<div class="item w2"></div>
<div class="item"></div>
<div class="item w2 h2"></div>
<div class="item"></div>
<div class="item w2"></div>
<div class="item"></div>
<div class="item h2"></div>
<div class="item"></div>
<div class="item h2"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item h2"></div>
<div class="item"></div>
<div class="item"></div>
</div>
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.packery {
background: #FDD;
background: hsla(45, 100%, 40%, 0.2);
margin: 0 auto;
}
/* clearfix */
.packery:after {
content: ' ';
display: block;
clear: both;
}
.item {
width: 150px;
height: 60px;
float: left;
background: #C09;
border: 4px solid #333;
border-color: hsla(0, 0%, 0%, 0.3);
}
.item.w2 { width: 320px; background: #9C0; }
.item.h2 { height: 120px; background: #0C9; }
// https://packery.metafizzy.co/packery.pkgd.js added as external resource
// overwrite Packery methods
var __resetLayout = Packery.prototype._resetLayout;
Packery.prototype._resetLayout = function() {
__resetLayout.call( this );
// reset packer
var parentSize = getSize( this.element.parentNode );
var colW = this.columnWidth + this.gutter;
this.fitWidth = Math.floor( ( parentSize.innerWidth + this.gutter ) / colW ) * colW;
this.packer.width = this.fitWidth;
this.packer.height = Number.POSITIVE_INFINITY;
this.packer.reset();
};
Packery.prototype._getContainerSize = function() {
// remove empty space from fit width
var emptyWidth = 0;
for ( var i=0, len = this.packer.spaces.length; i < len; i++ ) {
var space = this.packer.spaces[i];
if ( space.y === 0 && space.height === Number.POSITIVE_INFINITY ) {
emptyWidth += space.width;
}
}
return {
width: this.fitWidth - this.gutter - emptyWidth,
height: this.maxY - this.gutter
};
};
// always resize
Packery.prototype.needsResizeLayout = function() {
return true;
};
// init packery
var container = document.querySelector('.packery');
var pckry = new Packery( container, {
itemSelector: '.item',
columnWidth: 150,
gutter: 20
});
Also see: Tab Triggers