A Pen by David DeSandro on CodePen.
Created
February 12, 2016 08:37
-
-
Save omero/770c738dcfec3aa38cf3 to your computer and use it in GitHub Desktop.
Masonry - imagesLoaded progress
This file contains hidden or 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</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 hidden or 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 Masonry | |
var $grid = $('.grid').masonry({ | |
itemSelector: '.grid-item', | |
percentPosition: true, | |
columnWidth: '.grid-sizer' | |
}); | |
// layout Isotope after each image loads | |
$grid.imagesLoaded().progress( function() { | |
$grid.masonry(); | |
}); |
This file contains hidden or 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="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
<script src="http://masonry.desandro.com/masonry.pkgd.js"></script> | |
<script src="http://imagesloaded.desandro.com/imagesloaded.pkgd.js"></script> |
This file contains hidden or 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