Skip to content

Commit a2dc06c

Browse files
committed
feat(player core): added onhover function
1 parent 5cb47ff commit a2dc06c

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/Player.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,18 @@ export class Player extends React.Component<IPlayerProps, IPlayerState> {
248248
}
249249

250250
private async createLottie() {
251-
const { autoplay, direction, loop, lottieRef, renderer, speed, src, background, rendererSettings } = this.props;
251+
const {
252+
autoplay,
253+
direction,
254+
loop,
255+
lottieRef,
256+
renderer,
257+
speed,
258+
src,
259+
background,
260+
rendererSettings,
261+
hover,
262+
} = this.props;
252263
const { instance } = this.state;
253264

254265
if (!src || !this.container) {
@@ -323,6 +334,18 @@ export class Player extends React.Component<IPlayerProps, IPlayerState> {
323334
}
324335
});
325336

337+
// Set handlers to auto play animation on hover if enabled
338+
this.container.addEventListener('mouseenter', () => {
339+
if (hover && this.state.playerState !== PlayerState.Playing) {
340+
this.play();
341+
}
342+
});
343+
this.container.addEventListener('mouseleave', () => {
344+
if (hover && this.state.playerState === PlayerState.Playing) {
345+
this.stop();
346+
}
347+
});
348+
326349
// Set initial playback speed and direction
327350
if (speed) {
328351
this.setPlayerSpeed(speed);

0 commit comments

Comments
 (0)