-
Notifications
You must be signed in to change notification settings - Fork 27
How to properly remove event listener on window.object? #82
Comments
Hey @sebastianjung, glad you're enjoying the lib :) It sounds like you're creating a new instance of ASScroll every time you navigate to another page. The idea is to create a single instance that you then disable and enable accordingly, passing your new page element to the Here is an example using the PJAX library Highway which should explain the same concept: https://codepen.io/ashthornton/project/editor/AypMLG Let me know if this helps. |
@ashthornton Thank you very much for looking into this. sadly i was not able to import the library as it throws "self is not defined" error. I am only able to use the library when the app is already mounted via an import('@ashthornton/ass...) statement. Not sure what is causing this issue but i can't get it to work. I tried a workaround where i initted only one instance and reuse this between revitis of the page using the scroll but that also leads to unexpected behaviour: Before i was putting the containerElement inside the options object on instance creation. But now i have to put it inside asscroll.enable({ newScrollElements: '...' }) if I'm not mistaken. Changing this leads to the content not being visible at times. Second half shows the behaviour: Noticable things:
This is my code now:
and before i change route i call this:
Appreciate your help a lot! Let me know if you need any more info on that. EDIT: Is containerElement the same element as newScrollElements and the same as the one having asscroll-container attribute applied to it? I'm confused on whether i need asscroll-container attribute + newScrollElements at the same time. |
@ashthornton The thing that's conflicting in my head is the following: Wouldn't it be more logical to destroy the instance as well or provide a possibility to reset the instance values somehow? (containerElement). I'm probably overseeing things here. Sorry to bother you! |
Hey there,
first of all thank you for the awesome library. Was actually the only one i found which fits the need of the project i'm working on.
I'm using it in conjuction with nuxt 2 / vue 2 and having a hard time making it work correctly.
Reproducing the error:
For further information you might want to check out the bug yourself here:
https://front.ausbildung.stage.sma.pippis.zone/berufsbilder-und-studiengaenge
Click one of the items and go back in browser history and revisit one item.
When i looked into it more i found out that the event listeners on the window object are not removed when using asscroll.disable() or asscroll.off('update', someRandomFunction)
Instead they get duplicated for each revisit of the site.
Is this intended behaviour? And If so: How to properly disconnect the scroll listener on window object on site-leave / beforeDestroy()
Any help is very much appreciated.
And again: Thank you for the library!
Sebastian
EDIT:
Some more info:
In mounted() i init asscroll with this function:
I think the gsap stuff can be ignored as uncommenting it and using asscroll with its own RAF does not solve the problem.
The text was updated successfully, but these errors were encountered: