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

Height issue #16

Closed
mehtabfarooq opened this issue Jul 27, 2022 · 3 comments
Closed

Height issue #16

mehtabfarooq opened this issue Jul 27, 2022 · 3 comments

Comments

@mehtabfarooq
Copy link

Hi, thanks for creating such an awesome library. I am facing an issue while images are loading, it is not getting their full height. I can't use fixed height in my case, so what the solution would be apart for fixed height for images?

@Spope
Copy link
Owner

Spope commented Jul 29, 2022

If you don't know your image's height / width, my guess would be to listen to image's onload event to re-trigger a layout()

@jayelkaake
Copy link

jayelkaake commented Jan 16, 2023

To solve this I did this, where masonryElement is an HTMLElement that your masonry is attached to and masonryInstance is the masonry object instance:
masonryElement.querySelectorAll('img').forEach((img) => img.addEventListener('load', () => masonryInstance.layout()))

I also debounced this to avoid updates too frequently.

Hope that helps someone else in the future assuming you've already solved the issue!

@Spope
Copy link
Owner

Spope commented Jan 16, 2023

Thanks for your comment, this and the debounce looks like good to me, I'm going to close this issue.

@Spope Spope closed this as completed Jan 16, 2023
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