7

Using framer motion I want to animate my Icon component to rotate 90 degrees when hovering at the parent element which is a button.

<motion.button type="button" whileHover={{scale: 1.1}}>
    Visit our Industry 
    {/*Animate this Icon to rotate 90 degrees*/}
    <Icon type="arrow-up" /> 
</motion.button>

I saw the use of variants but not sure how to really use them with props like whileHover.

Any help will be appreciated since this is a new thing.

Sam Denty
  • 3,024
  • 3
  • 19
  • 33
ArchNoob
  • 2,803
  • 3
  • 25
  • 51

2 Answers2

16

You need to set 'whileHover' to a string and use the varients to animate.

https://codesandbox.io/s/heuristic-wozniak-2z01b

zero
  • 699
  • 8
  • 18
0

Tho The first answer is very sufficient enough, here is some concept from the doc:

Propagation : If a motion component has children, changes in variant will flow down through the component hierarchy. These changes in variant will flow down until a child component defines its own animate property.

So that means by default child motion components will inherit the parent variant and act as the same, until you specify their own.

Check out the doc: PROPAGATION

ObinasBaba
  • 192
  • 6