I'm using Masonry for a project and applying imagesLoaded accordingly.
After many, many tests I figured out these two work almost perfectly together, but sometimes they'd fail. And 99% of the cases it's imagesLoaded's fault.
However it seems that on Internet Explorer imagesLoaded fails to load a lot more than in any other browser.
Here's what I've found:
- If you open a new tab and enter the URL directly -> imagesLoaded works
- If you hit refresh -> imagesLoaded works
- If you type in the URL, hit refresh, mark the text in the address bar and press Enter -> imagesLoaded fails
- If the above actions are repeated with the console open -> imagesLoaded works
- And sometimes it doesn't work if it feels like it...
What's the deal here? This only occurs in Internet Explorer (11, 10, 9, etc.).
Here's the JS:
function masonryOptions(){
$('.post-wrapper').width((((($('#content').width() - ((columnCount*gutter) - gutter)) / columnCount) / $('#content').width()) * 100)+'%');
$(window).resize(function() {
$('.post-wrapper').width((((($('#content').width() - ((columnCount*gutter) - gutter)) / columnCount) / $('#content').width()) * 100)+'%');
});
container.imagesLoaded(function(){
$('iframe').load(function() {
container.masonry({
itemSelector: '.post-wrapper',
gutter: gutter,
transitionDuration: 0
});
});
});
}
$(document).ready(function(){
masonryOptions();
});
And a demo page: http://lorem-blogsum.tumblr.com/