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

Listen for document resize? #32

Closed
Cevorob opened this issue Jan 7, 2022 · 7 comments · Fixed by #36
Closed

Listen for document resize? #32

Cevorob opened this issue Jan 7, 2022 · 7 comments · Fixed by #36

Comments

@Cevorob
Copy link

Cevorob commented Jan 7, 2022

Hi, Im very happy with how immerser works, but I use it on a website with a lot of animations etc. and I cant make it without some javascript that affects document height (dropdowns, sliders,...). I saw a handleResize() function used on window resize, so I added ResizeObserver for the whole document and used the handleResize function in each entry. This solution works as I wanted, wouldnt it be a good idea to implement this in Immerser? Or mention it somewhere as a possible solution?

@dubaua
Copy link
Owner

dubaua commented Jan 9, 2022

Hello, thank you for feedback.

I assume ResizeObserver callback is firing after actual height of the document is changes, so you do not need schedule setting sizes and draw immerser. And you can call setSizes and draw methods in your callback.

I think I will add your approach in the documentation, but first I need to design and add a section for recipes ;)

@Cevorob
Copy link
Author

Cevorob commented Jan 10, 2022

I dont understant 100% what you said, but yes, the problem is with actual document height changes. My question can be simplified: why not add to this window.addEventListener('resize', this.onResize, false); some solution that listenes to actual document height changes?
Because when document height changes, immerser will always break. It needs to be recalculated... From my point of view its a no-brainer to add this feature :)

@dubaua
Copy link
Owner

dubaua commented Jan 10, 2022

We already have this here https://github.com/dubaua/immerser/blob/master/src/immerser.js#L237

Your problem is you change document height manually, and resize event isn't fired this case. Because resize event fired when you resize browser window. Instead of listen to window resize, you should manually call setSizes and draw methods on immerser instance after height is changed. You can do it after DOM manipulation.

@Cevorob
Copy link
Author

Cevorob commented Jan 10, 2022

Yes, thats what Im talking about. Shouldnt that be implemented from default?

@dubaua
Copy link
Owner

dubaua commented Jan 10, 2022

How can library know when DOM is manually changed?

@Cevorob
Copy link
Author

Cevorob commented Jan 10, 2022

Good question :D I got carried away with my specific case. I think it would be best to add this solution into recipes section as you said :)

@dubaua dubaua linked a pull request Jan 14, 2022 that will close this issue
@dubaua
Copy link
Owner

dubaua commented Jan 14, 2022

@Cevorob Hi!

I've just updated documentation, added recipe to handle DOM change and related immerser onDOMChange method. Please, check if it's okay and let me know.

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

Successfully merging a pull request may close this issue.

2 participants