Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id='container'>
<div>
              
            
!

CSS

              
                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);
}
              
            
!

JS

              
                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

Console