I've written a widget using the jQuery UI widget factory (in Typescript).
My widget listens for scroll events on the window element, so an event handler is added in the _create
function:
_create = function () {
$(window).on("scroll", this.handleScroll);
}
And in the _destroy
function I want to remove the handler:
_destroy = function () {
$(window).off("scroll", this.handleScroll);
}
However, there can be two instances of this widget on my page: one in the regular page, and one in a popup. My current implementation removes the handlers for both instances, which is clearly unwanted.
I've read this question: Recommended way to remove events on destroy with jQuery UI Widget Factory, the accepted answer there works fine for a custom event, but I cannot see a solution for a standard event like scroll
.
Any ideas appreciated.