Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get images to work with masonry/fluid #23

Open
vedant1811 opened this issue Jul 14, 2016 · 3 comments
Open

Can't get images to work with masonry/fluid #23

vedant1811 opened this issue Jul 14, 2016 · 3 comments

Comments

@vedant1811
Copy link

I have the following code:

In application.js:

//= require masonry/jquery.masonry

application.scss:

@import 'masonry/fluid';

<h1>Masonry + imagesLoaded, iteratively reveal items</h1>

<div id="masonry-container" class="centered masonry">
  <%= render @collection.models %>
</div>

_model.html.erb:

<div class="box">
  <%= image_tag(model.photos.first.photo.url(:medium)) %>
</div>

js.erb:

$(document).ready(function() {

    $('#masonry-container').masonry({
        itemSelector: '.box',
        // set columnWidth a fraction of the container width
        columnWidth: function( containerWidth ) {
            return containerWidth / 3;
        }
    });
});

But the images (usually much larger than containerWidth / 3) take up more space and the entire layout is messed up. Passing width: 300 in the image_tag prevents this, but defeats the purpose of a fluid width.

How can I get this to work?

@kristianmandrup
Copy link
Owner

Sounds like something specific to Masonry configuration, maybe an addon/plugin for masonry? See if you can find Masonry solutions/examples that function the way you desire with respect to automatic image resize.

@Judahmeek
Copy link
Collaborator

Judahmeek commented Jul 14, 2016

Some more information about how the layout is incorrect would be useful. If you have a fixed containerWidth and images larger than the desired columnWidth, than you'll at least need a max-width percent constraint in order to eliminate overflow effects.

@kristianmandrup
Copy link
Owner

You are always most welcome to make PRs for better docs in various usage scenarios which require special care. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants