Skip to content

Commit

Permalink
only draw frames when canvas is in viewport
Browse files Browse the repository at this point in the history
  • Loading branch information
reindernijhoff committed Apr 13, 2024
1 parent ab3dcf3 commit e36047f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/lib/FastImageSequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,18 @@ export class FastImageSequence {
// }
// }

const currentFrame = this.frames[index] as Frame;
currentFrame.getImage().then((image) => {
this.drawFrame(image, index);
}).catch(() => {
});

// check if canvas is in viewport
const rect = this.canvas.getBoundingClientRect();
const inViewport = rect.top < window.innerHeight && rect.bottom > 0;

if (inViewport) {
const currentFrame = this.frames[index] as Frame;
currentFrame.getImage().then((image) => {
this.drawFrame(image, index);
}).catch(() => {
});
}

this.load(dt);

Expand Down

0 comments on commit e36047f

Please sign in to comment.