score:2
You need to rebase your codes to it uses motion.div
.
For example, for your background color to change.
<div className="App">
<motion.div whileHover={{ backgroundColor: 'rgb(100,0,0)' }} style={{ backgroundColor: 'rgb(255,0,0)'}}>
Hover Me
</motion.div>
</div>
If you use the following, the div background will change, but it will not affect the background of the button unless u set style {{backgroundColor: 'inherit'}}
// following button background won't change color
<div className="App">
<motion.div whileHover={{ backgroundColor: 'rgb(100,0,0)' }} style={{ backgroundColor: 'rgb(255,0,0)'}}>
<button>I am a button</button>
</motion.div>
</div>
//following background of button will change color
<div className="App">
<motion.div whileHover={{ backgroundColor: 'rgb(100,0,0)' }} style={{ backgroundColor: 'rgb(255,0,0)'}}>
<button style={{ backgroundColor: 'inherit' }}>I am a button</button>
</motion.div>
</div>
Simple example https://codesandbox.io/s/cocky-kapitsa-nl5bs
For SVG it's the same thing.
<motion.svg initial={{.... }} animate={{ ..... }} whileHover={{ ..... }}>
<path d="M9.07903 14.9692L6.17405 12.1096C5.67622 11.6195 4.8712 11.6195 4.37337 12.1096C3.87554 12.5997 3.87554 13.3921 4.37337 13.8822L8.18311 17.6325C8.68094 18.1225 9.48597 18.1225 9.98379 17.6325L19.6266 8.14012C20.1245 7.65006 20.1245 6.8576 19.6266 6.36754C19.1288 5.87749 18.3238 5.87749 17.8259 6.36754L9.07903 14.9692Z"
fill="#ffffff"
strokeWidth="0.5"
stroke="#ffffff"
/>
</motion.svg>
If you want to animate individual paths you need to convert it to motion.path
<motion.svg initial={{.... }} animate={{ ..... }} whileHover={{ ..... }}>
<motion.path d="M9.07903 14.9692L6.17405 12.1096C5.67622 11.6195 4.8712 11.6195 4.37337 12.1096C3.87554 12.5997 3.87554 13.3921 4.37337 13.8822L8.18311 17.6325C8.68094 18.1225 9.48597 18.1225 9.98379 17.6325L19.6266 8.14012C20.1245 7.65006 20.1245 6.8576 19.6266 6.36754C19.1288 5.87749 18.3238 5.87749 17.8259 6.36754L9.07903 14.9692Z"
initial={{ opacity: 0 }}
animate={{ fill: "#ffffff", opacity: 1 }}
strokeWidth="0.5"
stroke="#ffffff"
/>
</motion.svg>
Source: stackoverflow.com
Related Query
- I want to create a custom radioButton with framer-motion
- Framer Motion exit animation not firing on accordion with react-router-dom
- How to create custom React Native components with child nodes
- How to Create Custom Dropdown Field Component with Redux-Form V6?
- How can I create a custom page with #react-admin without the menu sidebar like login page?
- staggerChildren with framer motion
- React-router-dom (v6) with Framer Motion (v4)
- How to create a custom equality function with reselect and Typescript?
- Framer Motion - stale custom value - changing the custom value doesn't trigger an update
- Snapping to position onDragEnd with motionValues using Framer Motion and React
- How can I create custom Tabs with multiple labels per tab in material UI?
- Is there a way that I can create a custom column with auto numbering in material-table?
- ReactJS: create element with custom type programatically?
- How to create custom attr name with styled component?
- Create custom style Material UI with redux-form
- with draft.js is it possible to create a custom block span with classname
- Cannot create custom style with React and Bootstrap
- Draft-JS - How to create a custom block with some non-editable text
- How do you animate menu with framer motion on-click?
- Create custom hook without passing props in React with Typescript
- If I create custom Button with material-ui ButtonGroup doesnt work
- Framer Motion and React router 5: How do I prevent re-render of parent components with nested routes?
- REACT: How to create a reusable custom hook with functions and effects that can change & react to changes in a host component's data
- Framer motion and exit property not working with InertiaJs
- create five bullet points programmatically in react? Users can add tasks, but I want to start with initial variable number of bullets
- Animate SVG along path with Framer Motion
- Is it possible to use Framer Motion in React with pug
- Question about running multiple animations in sequence with Framer Motion
- StaggerChildren is not working with Framer Motion
- ReactJS - Custom hook to create a single object with the data collected from multiple form components
More Query from same tag
- Enzyme's shallow().text() with React Native doesn't work as I expected
- How can we plot histogram graph with Apache Echart.js with Single bar highlighted with custom tooltips?
- 'React Hook useEffect has a missing dependency' warning with function
- Why I can't see my objects in chrome console in react?
- Separate Css files in typescript react project do not apply
- Problem with yarn when trying to set a ruby on rails application with react
- How to load selected language when page refresh
- TypeError: userData.map is not a function even though userData is an array
- React, getting Error: Invalid hook call. Hooks can only be called inside of the body of a function component
- Map and Render a Subarray in ReactJS
- Pass down function with multiple parameters to child component w/ TypeScript
- ReactJS - firebase how query a record with particular .key
- How can I change what is rendred with a click event in React
- Getting a TypeScript error with redux dispatch in my React app
- How to switch from one screen to another after a certain time in ReactJS?
- How to add Radio Button in Formik Validations Reactjs?
- What should I use to show live icons in React OR Javascript? Like how much coffee is filled in a mug?
- Accessing cookies from React SSR
- update the defaultValue on re
- useEffect is not being called when dependency is changed
- Component rendering before ComponentDidMount and Axios sets the state
- Setting children in defaultProps
- Unexpected use of 'screen' no-restricted-globals reactjs
- React passing link to reusable component
- TypeError: this.props.logout is not a function
- Render a React component from a button click event
- React. Unhandled Rejection (TypeError): Cannot read property 'value' of undefined
- React Functional Component: How to prevent form from submitting if validation failed
- use another useeffect result in another
- How can I add icons Fontawesome in react?