"masonry Image Gallery"
Bootstrap 4.0.0 Snippet by rhenggha

<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <h1>Masonry + imagesLoaded, iteratively reveal items</h1> <div id="container"></div> <div id="images"> <div class="item"> <img src="https://picsum.photos/530/290/?random"> </div> <div class="item"> <img src="https://picsum.photos/100/290/?random"> </div> <div class="item"> <img src="https://picsum.photos/400/500/?random"> </div> <div class="item"> <img src="https://picsum.photos/300/450/?random"> </div> <div class="item"> <img src="https://picsum.photos/530/290/?random"> </div> <div class="item"> <img src="https://picsum.photos/400/250/?random"> </div> <div class="item"> <img src="https://picsum.photos/400/250/?random"> </div> <div class="item"> <img src="https://picsum.photos/530/290/?random"> </div> <div class="item"> <img src="https://picsum.photos/100/290/?random"> </div> <div class="item"> <img src="https://picsum.photos/400/500/?random"> </div> <div class="item"> <img src="https://picsum.photos/300/450/?random"> </div> <div class="item"> <img src="https://picsum.photos/530/290/?random"> </div> <div class="item"> <img src="https://picsum.photos/400/250/?random"> </div> <div class="item"> <img src="https://picsum.photos/400/250/?random"> </div> </div> <p> <button id="load-images">Load images</button> <script src="//masonry.desandro.com/masonry.pkgd.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/3.0.4/jquery.imagesloaded.js"></script> </div> </p>
body { font-family: sans-serif; } #container { background: #DDD; max-width: 1400px; } .item { width: 200px; float: left; } .item img { display: block; width: 100%; } button { font-size: 18px; } .container{ width:100%; }
$(function () { var $container = $('#container').masonry({ itemSelector: '.item', columnWidth: 200 }); // reveal initial images $container.masonryImagesReveal($('#images').find('.item')); }); $.fn.masonryImagesReveal = function ($items) { var msnry = this.data('masonry'); var itemSelector = msnry.options.itemSelector; // hide by default $items.hide(); // append to container this.append($items); $items.imagesLoaded().progress(function (imgLoad, image) { // get item // image is imagesLoaded class, not <img>, <img> is image.img var $item = $(image.img).parents(itemSelector); // un-hide item $item.show(); // masonry does its thing msnry.appended($item); }); return this; };

Related: See More


Questions / Comments: