Created
November 4, 2014 17:10
-
-
Save desandro/f2a6cc83cf89aec3d880 to your computer and use it in GitHub Desktop.
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
// jQuery | |
$( function() { | |
$('.js-masonry.imgload').each( function( i, elem ) { | |
var $elem = $(elem).imagesLoaded( function() { | |
var attr = $elem.attr('data-masonry-options'); | |
var options = attr && JSON.parse( attr ); | |
$elem.masonry( options ); | |
}); | |
}); | |
}); | |
// vanilla JS | |
docReady( function() { | |
var elems = document.querySelectorAll('.js-masonry-imgload'); | |
function imgLoadMasonry( elem ) { | |
var attr = elem.getAttribute('data-masonry-options'); | |
var options = attr && JSON.parse( attr ); | |
// init masonry after images have been loaded | |
imagesLoaded( elem, function() { | |
new Masonry( elem, options ); | |
}); | |
} | |
for ( var i=0, len = elems.length; i < len; i++ ) { | |
var elem = elems[i]; | |
imgLoadMasonry( elem ); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment