Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Masonry Layout with Bootstrap Tabs

H,

When you click on the second tab, the pictures are stacked all on each other. But if you resize the window, or even open inspect tool, the images will go to masonry layout.

How can i make so when the user clicks, they will be loaded already? because obeviously no user will resize their screen and think it doesn't work, which it doesn't work 50%.

codepen Click the second tab and resize.

And here with my own tabs with no bootstrap.

codepen

1 Answer

Steven Parker
Steven Parker
243,200 Points

Hi again Konrad,

I'm not familiar with "masonry", but a quick look at the guide indicates that it needs to be called after the images are loaded.

Adding the event handler from the guide didn't do anything, but I began to wonder if masonry couldn't do the job while the images were not shown. So I tried adding a handler to call it when tab two is clicked and the images are revealed.

And that seems to work!

  // layout masonry when tab 2 is clicked
  $("li[data-tab=tab-2]").click(function() {
    $('.masonry-container').masonry('layout');
  });

(I was working with the "no bootstrap" version)

Thank you. I didn't check the documentation properly : p