A Pen by David DeSandro on CodePen.
Created
August 12, 2016 14:35
-
-
Save joelgarzatx/191cccc07ba5dfc59038184c5784c87d to your computer and use it in GitHub Desktop.
Masonry - imagesLoaded progress, vanilla JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Masonry - imagesLoaded progress, vanilla JS</h1> | |
<div class="grid"> | |
<div class="grid-sizer"></div> | |
<div class="grid-item"> | |
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/orange-tree.jpg" /> | |
</div> | |
<div class="grid-item"> | |
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/submerged.jpg" /> | |
</div> | |
<div class="grid-item"> | |
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/look-out.jpg" /> | |
</div> | |
<div class="grid-item"> | |
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/one-world-trade.jpg" /> | |
</div> | |
<div class="grid-item"> | |
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/drizzle.jpg" /> | |
</div> | |
<div class="grid-item"> | |
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/cat-nose.jpg" /> | |
</div> | |
<div class="grid-item"> | |
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/contrail.jpg" /> | |
</div> | |
<div class="grid-item"> | |
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/golden-hour.jpg" /> | |
</div> | |
<div class="grid-item"> | |
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/flight-formation.jpg" /> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// external js: masonry.pkgd.js, imagesloaded.pkgd.js | |
// init Isotope | |
var grid = document.querySelector('.grid'); | |
var msnry = new Masonry( grid, { | |
itemSelector: '.grid-item', | |
columnWidth: '.grid-sizer', | |
percentPosition: true | |
}); | |
imagesLoaded( grid ).on( 'progress', function() { | |
// layout Masonry after each image loads | |
msnry.layout(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="http://masonry.desandro.com/masonry.pkgd.js"></script> | |
<script src="http://imagesloaded.desandro.com/imagesloaded.pkgd.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { box-sizing: border-box; } | |
/* force scrollbar */ | |
html { overflow-y: scroll; } | |
body { font-family: sans-serif; } | |
/* ---- grid ---- */ | |
.grid { | |
background: #DDD; | |
} | |
/* clear fix */ | |
.grid:after { | |
content: ''; | |
display: block; | |
clear: both; | |
} | |
/* ---- .grid-item ---- */ | |
.grid-sizer, | |
.grid-item { | |
width: 33.333%; | |
} | |
.grid-item { | |
float: left; | |
} | |
.grid-item img { | |
display: block; | |
max-width: 100%; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment