-
Notifications
You must be signed in to change notification settings - Fork 2k
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
listener for DOMContentLoaded and window resize #1384
Comments
For this particular case you may want to consider:
The first will fire much less often than a resize event. The second removes the need for JS entirely :) |
Thanks Eric. In this particular case, I managed to get around it (and I've written a blog about my experience on this topic - coming out later this month, since my blog is backlogged several days right now). Neither of these worked because of the nature I wanted to get out of my component. Short version is that I wanted to do:
Inside the web component, I have a DIV that is 30% of the height of the component. I wanted to make the component be square (instead of just the height of the DIV) and the font-size style property to scale with the size of the containing DIV. Since the containing DIV can be anything (I envisioned using the same component in several pages since it's just encapsulated content), the media queries and viewport units would not work. I ended up using the following code:
It has a small problem if you don't have a script tag at the bottom of the page - DOMContentLoaded fires before style has set up the size of all the elements, meaning that the dnd-gridcharacter object is zero width. Solution was to put a script block at the end. My complete web component is here: https://github.com/adrianhall/blog-code/tree/master/CharacterSheet/src/elements/dnd-gridcharacter |
One of the concrete things I want to do is to resize a font within the shadow DOM when the window is resized. However the attached event fires before the DOM is ready and I can't just listen to resize events on an object. It would be ideal to enable something like:
Alternative / workaround is to use addEventListener to set the event handler.
The text was updated successfully, but these errors were encountered: