Aspect ratio does not update when tsparticles' element changes size, but the window has not changed size
See original GitHub issueIn Vanilla JS version 1.26.0 if tsparticles’ DOM element resizes, the canvas render becomes distorted. I’ve enabled resize: true
, and upon manually resizing the window, tsparticles adjusts as expected. This however does not solve when a page reflows happens and all elements in a flexbox update with new widths and heights, one of which children is tsparticles.
QUESTION: Is there a way to have tsparticles auto-detect if its element (or parent) has changed size as a result of a reflow without a window resize occurring?
I’ve temporarily injected a resize event as a result of page changes which corrects the aspect ratio, but this doesn’t seem very elegant.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to make tsParticles full width and height of a container ...
I have been struggling trying to get particles.js to be the background of a given element. That library seems to position the canvas...
Read more >Options | tsParticles - v2.6.0
Enables the retina detection, if disabled the ratio used by canvas will be always 1 and not the device setting. Implementation of IOptions.detectRetina....
Read more >Image size not updating after toolbar resize - Stack Overflow
The replaced content is sized to maintain its aspect ratio while filling the element's entire content box. If the object's aspect ratio does...
Read more >Keep it contained!. Enforcing an aspect ratio on an HTML…
Frequently, it's necessary to set an aspect ratio on an element (like a <div> element), so that it will maintain its shape while...
Read more >Lightweight JS Library For Creating Interactive Particles
tsparticles is an upgraded and continued version of the ... react-particles-js, but I decided to not change the major version since all the ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @matteobit, Thank you for the response, and confirmation the workaround is currently best practice. It would be a nice if
resize
observed both the window and parent element to ensure aspect ratio is always correct in a responsive page.tsparticles is amazing and I’m enjoying working with it!
Thanks for the snippet to access the canvas resize function. You have a good point about particle density. In my use case, a slider adjusts the size of sibling containers which causes rapid-fire updates, so I think:
canvas.resizeWindow()
will keep aspect ratios correct, and thenThis should make it nearly indiscernible to the eye.
Even the simplest things have edge cases to manage!!