How to make tsParticles full width and height of a container and not the whole page?
See original GitHub issueI have been struggling trying to get particles.js to be the background of a given element. That library seems to position the canvas weirdly and it always makes the canvas wider and longer than the element, and hacking around with top
and left
doesn’t really work well either. As far as I can tell it assumes you only ever want the whole page background to be it’s canvas. so I decided to look into tsParticles.
Does tsParticles properly support working with an arbitrary element and it’s width and height, e.g. it would use these values to create the canvas correctly? If the div is 100px wide and 100px in height, the canvas would be 100px wide and 100px in height.
For example, I have a div in the center. I’d like tsParticles to render only inside the div and underneath the text:
Would it be possible to get an example of this?
Issue Analytics
- State:
- Created 3 years ago
- Comments:18 (7 by maintainers)
Hi @lloydjatkinson,
Yes, this configuration is possible. You can see that working in these samples
https://codepen.io/matteobruni/pen/XWjLOpQ
https://codepen.io/matteobruni/pen/QWKXPRq
I try to explain how to achieve it.
Don’t enable
backgroundMode
options or use any kind of fixed CSS on that div.The best result will be achieved using a container for particles and your content like this:
Hope it helps, if you need more help don’t hesitate to ask
The configuration object has an issue for
fullScreen
options.I’ve fixed the
fullScreen
issues, I didn’t change anything in other options.