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

Grid dimensions only calculated on window resize #81

Open
richardpbull opened this issue Dec 31, 2020 · 9 comments
Open

Grid dimensions only calculated on window resize #81

richardpbull opened this issue Dec 31, 2020 · 9 comments

Comments

@richardpbull
Copy link

Hello,
I must be doing something wrong as everywhere else I read about this it is working perfectly.
I can't get the instance to resize on all images loading.
The images remain overlapped until I resize the browser. Video below:

gallery.resize.mov

Here's the code being used on this example: https://www.ultratourmonterosa.com/gallery/

Help appreciated!
Thank you.

var macy_instance = Macy({
	container: '#photos',
	trueOrder: false,
	waitForImages: true,
	margin: 6,
	columns: 3,
	breakAt: {
			1200: 3,
			940: 3,
			520: 2,
			400: 1
		}
	});
	macy_instance.runOnImageLoad(function () {
		console.log('I only get called when all images are loaded');
		macy_instance.recalculate(true, true);
	});
@ve3
Copy link

ve3 commented Jan 25, 2021

Confirm the same problem.

let macyInstance = new Macy({
    'columns': 3,
    'container': '#rdba-dashboard-row-normal'
});

@kuipumu
Copy link

kuipumu commented Mar 8, 2021

I'm having the same issue, any fix?.

image

@jrmd
Copy link
Member

jrmd commented Mar 8, 2021

hey @richardpbull @kuipumu

You could try running the recalculate event on each image load; the issue seems to be if an image has failed to load (or if it does it too quick) then it can cause issues with the event finishing you can try doing it like so here:

macy_instance.runOnImageLoad(function () {
  console.log('Every time an image loads I get fired');
  macy_instance.recalculate(true, true);
}, true);

@kuipumu
Copy link

kuipumu commented Mar 10, 2021

Hi @richardpbull adding the recalculate event didn't fixed the issue, the problem was that if no src is present on each image macy.js fails to give a correct height, and unless you resize the windows the grid will be shown has previously captured.

@c8e4d2a
Copy link

c8e4d2a commented May 5, 2021

same issue, src is present in all images

@c8e4d2a
Copy link

c8e4d2a commented May 5, 2021

Dirty Fix:

macyInstance.runOnImageLoad(function () {
            macyInstance.recalculate(true, true);
            var evt = document.createEvent('UIEvents'); 
            evt.initUIEvent('resize', true, false, window, 0); 
            window.dispatchEvent(evt);
    }, true);

@Syed25794
Copy link

This dirty code didn't work for me. I fixed it by setTimeout function. Whenever I'm fetching the images and got the response after I setTimeout with 1 sec and define macy instance in setTimeout function. You can try also.

@joworeiter
Copy link

Setting waitForImages: false seems to solve the issue for me.

@talissonf
Copy link

I had this issue as well, and in my case, it happened because I was using VUE. Whenever I added new elements to the grid or tried to use the recalculate() or reInit() functions, the changes weren't being reflected in the application due to Vue's reactivity system.

The only solution that worked for me was to create a reference (ref) for the grid element I was using and then use this ref as the key for the grid. Every time I called the recalculate() function, I updated the value of my ref.

I believe if you're using this library with a framework like Vue or React, the same thing might be happening. With React, I think the solution to the problem would be the same.

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

8 participants