react-lottie icon indicating copy to clipboard operation
react-lottie copied to clipboard

How to trigger animation on hover?

Open magtanggol03 opened this issue 5 years ago • 8 comments

Currently trying to do it using the following but to no avail:

      <Lottie options={defaultOptions}
        height={100}
        width={100}
        isStopped={hover['isStopped']}
        direction={hover['direction']}
        eventListeners={
        	[
                { eventName: 'onMouseOver', callback: () => mouseOn() },
        	{ eventName: 'onMouseLeave', callback: () => mouseOut() }
        	]
        }
      />

Basically goal was to trigger the animation on hover, then reverse the animation when leaving.

magtanggol03 avatar Aug 17 '19 16:08 magtanggol03

lottie: ?Lottie;
const defaultOptions = {
	loop: true,
	autoplay: false,
	animationData: animationData
};
<div
	onMouseEnter={() => this.lottie && this.lottie.animation.play()}
	onMouseLeave={() => this.lottie && this.lottie.animation.pause()}>
	<Lottie
		ref={(ref) => this.lottie = ref}
		options={defaultOptions}/>
</div>

goldmont avatar Sep 06 '19 19:09 goldmont

@chenqingspring eventListeners prop is not working as indicated by this issue.

jeffal avatar Oct 17 '19 20:10 jeffal

Facing same issue, anyone have solution of it?

sanket-zeus avatar Nov 12 '20 14:11 sanket-zeus

Same issue, anyone able to trigger animation on hover?

rheng001 avatar Nov 25 '20 21:11 rheng001

Here is a screenshot of my code. Similar to goldmont, but I toggle the handleClickToPause function. Screen Shot 2020-11-25 at 3 25 56 PM

jeffal avatar Nov 25 '20 21:11 jeffal

@jeffal Thanks! I'll be sure to try it out 👍

rheng001 avatar Nov 25 '20 21:11 rheng001

Hello every one it is working for me, I have used onMouseEnter and onMouseLeave on the parent container.

This is my code :

import React, { useState } from 'react'
import Lottie from 'react-lottie';
import styles from './styles.module.css'


export default function Feature({title,description,lottieData}) {

  const options = {
    loop: false,
    autoplay: false,
    animationData: lottieData,
    rendererSettings: {
      preserveAspectRatio: "xMidYMid slice"
    }
  };

  const [stopped,setStopped]=useState(true)

  return (
    <div 
      className={styles.feature} 
      onMouseEnter={()=>{setStopped(false)}} 
      onMouseLeave={()=>{setStopped(true)}}
    >
        <Lottie options={options} isClickToPauseDisabled isStopped={stopped} />
        
        <div>
          <h3>{title}</h3>
          <p>{description}</p>
        </div>
    </div>
  )
}

I hope this will be helpful ^^

zeghmouri avatar Nov 23 '22 15:11 zeghmouri