css-grid-polyfill icon indicating copy to clipboard operation
css-grid-polyfill copied to clipboard

Callback on polyfill finish

Open niutech opened this issue 8 years ago • 6 comments

How can I run a callback function as soon as the polyfill finishes its work and the web page is ready?

niutech avatar Sep 28 '17 14:09 niutech

That's a good question; I don't think there is a way to know this currently.

Technically the polyfills runs at all times and updates as necessary, so I don't really know when you can decide it has finished, though I guess an event firing on an element as soon as it has finished layout would help a lot already.

FremyCompany avatar Sep 29 '17 04:09 FremyCompany

Btw I think what I just proposed would be to add

d.element.dispatchEvent(new Event("gridLayoutUpdated")); 
// actually Event is not constructible in IE11 so we would need to use the older createEvent but I don't know the exact syntax anymore, would have to look it up

at the end of a relayout pass:

https://github.com/FremyCompany/css-grid-polyfill/blob/master/src/css-grid/lib/grid-layout.js#L1419

Could you try this out, and tell me if that works for you? If it does, feel free to create a pull request or if you don't have time just tell it here and I'll try to make the actual change myself then.

FremyCompany avatar Sep 29 '17 04:09 FremyCompany

Yes, this is the place where I have put my callback invocation too. Generally it works, but many times it is too early - only after the second or third relayout the web page is ready. Is there a way to predict how many relayouts are necessary? Thanks!

niutech avatar Sep 29 '17 12:09 niutech

Are you using images, web fonts, or loading content dynamically? I guess what you want is for those to be ready and a relayout has happened after that; how to achieve that is a question I can't answer without seeing actual content

FremyCompany avatar Oct 01 '17 06:10 FremyCompany

This is the website in question: http://www.nexocode.ch. It is a static website with images and a recaptcha. Try opening it in a browser not supporting CSS Grid Layout. I want to show a full page loader in this case. For now, I am hiding it on the first relayout, but many times the page is not ready yet.

Secondly, sometimes the footer is not positioned properly and there is some white space below it. Do you know why is it so?

Thanks!

niutech avatar Oct 01 '17 09:10 niutech

Because of this issue, I had to use absolute positioning instead of CSS Grid Layout on that page.

niutech avatar Oct 06 '17 11:10 niutech