Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Gestures and Hover Effects | Interactive Animations
Animations in React with Framer Motion

bookGestures and Hover Effects

When you want your React components to react to user gestures, Framer Motion provides two powerful props: whileHover and whileTap. These props let you define how a component should animate in response to user interactions. The whileHover prop triggers an animation when the user hovers over the component with their mouse, while the whileTap prop animates the component when it is pressed or tapped. This allows you to create interactive feedback that feels smooth and intuitive for users. Both props accept an object that describes the animation you want to apply during the interaction. When the gesture ends—such as when the mouse leaves or the tap is released—the component smoothly returns to its original state or to the next defined animation.

Suppose you want to animate a button so that it slightly enlarges when hovered and shrinks a bit when tapped. You can use Framer Motion's motion.button and pass in the whileHover and whileTap props to achieve this effect. Here is how you could do it:

import { motion } from "framer-motion";

function AnimatedButton() {
  return (
    <motion.button
      whileHover={{ scale: 1.1 }}
      whileTap={{ scale: 0.95 }}
      style={{
        padding: "12px 32px",
        background: "#007bff",
        color: "white",
        border: "none",
        borderRadius: "6px",
        cursor: "pointer",
        fontSize: "18px"
      }}
    >
      Click Me
    </motion.button>
  );
}

When you hover over the button, it grows to 110% of its original size. When you tap or press down on it, it shrinks to 95%. This immediate feedback helps users understand that their actions are being recognized by the interface.

question mark

Which Framer Motion prop is used to animate a component when it is pressed or tapped?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 1

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

bookGestures and Hover Effects

Свайпніть щоб показати меню

When you want your React components to react to user gestures, Framer Motion provides two powerful props: whileHover and whileTap. These props let you define how a component should animate in response to user interactions. The whileHover prop triggers an animation when the user hovers over the component with their mouse, while the whileTap prop animates the component when it is pressed or tapped. This allows you to create interactive feedback that feels smooth and intuitive for users. Both props accept an object that describes the animation you want to apply during the interaction. When the gesture ends—such as when the mouse leaves or the tap is released—the component smoothly returns to its original state or to the next defined animation.

Suppose you want to animate a button so that it slightly enlarges when hovered and shrinks a bit when tapped. You can use Framer Motion's motion.button and pass in the whileHover and whileTap props to achieve this effect. Here is how you could do it:

import { motion } from "framer-motion";

function AnimatedButton() {
  return (
    <motion.button
      whileHover={{ scale: 1.1 }}
      whileTap={{ scale: 0.95 }}
      style={{
        padding: "12px 32px",
        background: "#007bff",
        color: "white",
        border: "none",
        borderRadius: "6px",
        cursor: "pointer",
        fontSize: "18px"
      }}
    >
      Click Me
    </motion.button>
  );
}

When you hover over the button, it grows to 110% of its original size. When you tap or press down on it, it shrinks to 95%. This immediate feedback helps users understand that their actions are being recognized by the interface.

question mark

Which Framer Motion prop is used to animate a component when it is pressed or tapped?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 1
some-alt