Skip to content

Commit

Permalink
Pause animation if document is hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya committed Oct 4, 2024
1 parent df65d56 commit 8a90f1d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions resources/js/components/menu-images.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ export default class MenuImages extends React.Component<Props> {

componentDidMount() {
this.setAutoRotateTimer();
document.addEventListener('visibilitychange', this.handlePageVisibilityChange);
}

componentWillUnmount() {
this.clearAutoRotateTimer();
document.removeEventListener('visibilitychange', this.handlePageVisibilityChange);
}

render() {
Expand Down Expand Up @@ -115,6 +117,14 @@ export default class MenuImages extends React.Component<Props> {
);
};

private readonly handlePageVisibilityChange = () => {
if (document.hidden) {
this.clearAutoRotateTimer();
} else {
this.setAutoRotateTimer();
}
};

@action
private readonly handleTransitionEnd = (event: React.TransitionEvent<HTMLDivElement>) => {
if (event.propertyName !== 'transform' || event.currentTarget !== event.target) {
Expand Down

0 comments on commit 8a90f1d

Please sign in to comment.