cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

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.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              body {
  padding: 5px;
}
    
.grid-item {
  width: calc(33.33% - 10px);
  margin: 5px;
  -webkit-transition: -webkit-box-shadow .25s;
  transition: box-shadow .25s;
}
.grid-item:hover {
  cursor: pointer;
  -webkit-box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.5), 0 6px 20px 0 rgba(0, 0, 0, 0.6);
  box-shadow: 0 5px 10px 0 rgba(0, 0, 0, 0.5), 0 6px 20px 0 rgba(0, 0, 0, 0.6);
}
            
          
!
            
              var apiKey = '986e904143a37c668876552671aacde9',
    authorId = 'nhienhy',
    perPage = 10,
    startPage = 0;

// Main content container
var $container = $('#container');

// Masonry 
$container.masonry({
  itemSelector: '.grid-item',
  columnWidth: '.grid-item',
  percentPosition: true
});

var gallery; 

function loadImages(page, callback) {
  console.log('loadImages page: '+page);
  var url = 'https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=' + apiKey + '&user_id=' + authorId + '&per_page=' + perPage + '&page=' + page + '&format=json&nojsoncallback=1';
  $.getJSON(url, function(response) {
    if (response.stat === 'ok') {
      (function loadEachImg(arrPhotos, index) {
        if (index < arrPhotos.length) {
          var photo = arrPhotos[index];
          var link = 'https://farm' + photo.farm + '.staticflickr.com/' + photo.server + '/' + photo.id + '_' + photo.secret + '.jpg';
          var $newElem = $('<a href="'+link+'"><img class="grid-item " src=' + link + ' style="display: none"></a>');
          $container.append($newElem);
          // ensure that new image loaded before adding to masonry layout
          $newElem.imagesLoaded(function(){
            $newElem.show();
            $container.masonry( 'appended', $newElem, true );
            $container.masonry('layout');
            // Init lightGallery
            if (gallery) {
              gallery.destroy(true);
            }
            gallery = $container.lightGallery({
              thumbnail: true,
              animateThumb: true,
              showThumbByDefault: false,
            }).data('lightGallery'); 
            loadEachImg(arrPhotos, ++index);
          });
        } else {	// done looping
          if (callback) {
            callback();
          }
        }
      })(response.photos.photo, 0);
    }
  });
}
console.log('-----------loadImages');
loadImages(++startPage, function() {
  // make sure body has scroll therefore be able to do infinitescroll
  if (document.body.scrollHeight <= window.innerHeight) {
    loadImages(++startPage);
  }
});

// infinite scroll
var loadingImages = false;
$(document).scroll(function() {
  var docScrollTop = $(document).scrollTop();
  var endScroll = $(document).height() - $(window).height() - 100;
  if (!loadingImages && (docScrollTop > endScroll)) {
    loadingImages = true;
    loadImages(++startPage, function(){
      loadingImages = false;
    });
  }
});

            
          
!
999px
Loading ..................

Console