tengbao / vanta

Animated 3D backgrounds for your website
http://vantajs.com/
MIT License
5.55k stars 1.02k forks source link

Vanta effect will not destroy. Why? #125

Closed justsomeusername2020 closed 2 years ago

justsomeusername2020 commented 2 years ago

In my web page project, I want to add an option to disable the VantaJS dynamic background if desired.

Here's my example code, where I added a button that should be destroying the Vanta effect when clicked: https://jsfiddle.net/playdohsniffer/un6hx1q5/131/

As you can see, I'm using the example javascript exactly as is provided in the "Cleanup" section of the docs: https://github.com/tengbao/vanta#cleanup

Why does the Vanta not destroy when the button is clicked? Is this a bug?

Seems like it should work using vanilla Javascript. But the doc example mentions to use React's "componentWillUnmount". Is it required to use React? I'm not familiar with that framework at all...

tengbao commented 2 years ago

You cannot call destroy on the constructor itself. You need to save the initialized effect to a new variable, then call destroy on that. See working example: https://jsfiddle.net/40qz2w7u/

justsomeusername2020 commented 2 years ago

Many thanks for correcting me. Glad to see you're back!

For anyone viewing this in the future, here's a properly working example using plain Javascript: https://jsfiddle.net/playdohsniffer/un6hx1q5/133/