metafizzy / flickity

:leaves: Touch, responsive, flickable carousels
https://flickity.metafizzy.co
7.52k stars 605 forks source link

Scroll event continues to fire after destroy is called #482

Closed swixpop closed 5 years ago

swixpop commented 7 years ago

If I call flkty.destroy() while a slide transition is happening, the scroll event continues to fire. Other events are possibly firing as well. The result is that not all styles are being cleared from slides after destroy is called.

desandro commented 7 years ago

Thanks for reporting this bug. I'll have to take a look.

jbach commented 7 years ago

This can be reproduced via

flkty.next();
flkty.destroy()

Calling flkty._events = {}; after flkty.destroy(); stops events from being called, but this not enough, as the animation loop keeps going, even if I set flkty.isAnimating = false;.

Maybe adding

if ( !this.isActive ) {
  return;
}

to proto.animate would help stopping the animation immediately?

deerezzd commented 5 years ago

Has there been any progress on this?

jbach commented 5 years ago

@lebowski89 I’ve been monkey-patching it like this:


const proto = Flickity.prototype;

const _animate = proto.animate;
proto.animate = function () {
  if (!this.isActive) {
    return;
  }
  _animate.call(this);
};

const _destroy = proto.destroy;
proto.destroy = function () {
  _destroy.call(this);
  this._events = {};
};
desandro commented 5 years ago

@jbach Good call. I'll be adding a similar fix in.

desandro commented 5 years ago

This fix has been released with v2.2.0. Thanks again!