Skip to content

Commit

Permalink
🔨 Stop previous slideshow only when new images have loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoLegends committed Mar 23, 2018
1 parent 67a1dec commit 70c9255
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,15 @@ export default class KenBurnsCarousel extends HTMLElement {
}

set images(images: string[]) {
this._imgList = images;

if (arraysEqual(this._imgList, images)) {
return;
}

clearTimeout(this._timeout);
this._timeout = 0;

this._imgList = images;
if (images.length > 0) {
this.animate(images);
} else {
this.stop();
}
}

Expand Down Expand Up @@ -302,7 +300,15 @@ export default class KenBurnsCarousel extends HTMLElement {

const img = document.createElement('img') as HTMLImageElement;
img.src = images[0];
img.onload = () => insert(0, img);
img.onload = () => {
this.stop();
insert(0, img);
};
}

private stop() {
clearTimeout(this._timeout);
this._timeout = 0;
}
}

Expand Down

0 comments on commit 70c9255

Please sign in to comment.