electerious / basicScroll

Standalone parallax scrolling for mobile and desktop with CSS variables.
https://basicscroll.electerious.com
MIT License
3.63k stars 148 forks source link

Destroy method #6

Closed bovas85 closed 6 years ago

bovas85 commented 6 years ago

I use Nuxt and SPA behaviour and would like to know how to restart it (or destroy - recreate) on each route change as the method will stay alive globally but won't move the element anymore as the reference changed.

electerious commented 6 years ago

It's currently not possible to destroy an instance, but you can call instance.stop() and basicScroll will stop animating it. instance.remove() might be a good addition. Thanks for the idea.

bovas85 commented 6 years ago

No probs, that'd be fantastic as at the moment whenever I move to another dynamic route it will duplicate the instance and block the animation

electerious commented 6 years ago

Added a destroy function :) Could you please make a review of the code changes? Will make it part of the next release when everything is fine.

https://github.com/electerious/basicScroll/commit/3976d72b718ee6306a6ea5479ba1c7065f9817b7

bovas85 commented 6 years ago

shouldn't _destroy have an argument of index?

electerious commented 6 years ago

Not required. The index is part of there instance: https://github.com/electerious/basicScroll/commit/3976d72b718ee6306a6ea5479ba1c7065f9817b7#diff-e7ec20b0ed49ebd35a3718a4a5838760R374

electerious commented 6 years ago

New version is live: https://github.com/electerious/basicScroll/commit/491d6c56db8be1a8e147220504cac059d9257d27

bovas85 commented 6 years ago

Ah I see :) good stuff will test it on Monday