inorganik / countUp.js

Animates a numerical value by counting to it
https://inorganik.github.io/countUp.js
MIT License
8.03k stars 1.38k forks source link

Cleanup / Destroy #296

Open somegooser opened 1 year ago

somegooser commented 1 year ago

Is there any way to destory / cleanup countup after use?

Thanks!

inorganik commented 1 year ago

you can simply delete it:

const countUp = new CountUp('targetId', 5234);
countUp.start();

and later

delete countUp;
somegooser commented 1 year ago

Thank you for the comment but will this also delete events attached via enableScrollSpy?

inorganik commented 1 year ago

good point. You could do

delete window['onScrollFns'];
window.onscroll = null;

I really don't think you're going to get any performance wins by doing that.

inorganik commented 1 year ago

However if you deleted your countUp instance, and it was using scroll spy, you could get a null pointer exception, so I could add a detach method.

inorganik commented 1 year ago

This is published in v2.4.2