Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

destroy() not working #20

Open
artonomic opened this issue Jul 13, 2022 · 2 comments
Open

destroy() not working #20

artonomic opened this issue Jul 13, 2022 · 2 comments

Comments

@artonomic
Copy link

artonomic commented Jul 13, 2022

Normally I would disable the sticky sidebar for smaller screens (< 992px) by using the "minWidth" option, but I would like to try something different with the destroy function. I have created a fiddle to demonstrate the issue.

https://jsfiddle.net/kynham79/

You will notice that the sticky sidebar is disabled when the document is loaded, and when you resize above 992px it will stick as expected. Once you resize back below 992px, the sticky sidebar should be disabled, but it throws an error. Watch the console.

@vstruhar
Copy link

Seems that you need to initialise your sidebar variable outside, so it can be accessed from the scope where you call destroy().

image

@electronicdreamer
Copy link

electronicdreamer commented Nov 19, 2022

I had a problem with my destroy related to Vue 3 as version 3 uses proxies for everything.

Sticky sidebar makes use of the handleEvent function, which is the reason why the whole class is passed to the addEventListener but in Vue's case, when I called the destroy function, it called it on the proxy and not the real this so it couldn't unbind the event.

So I rewrote some of the code for my use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants