IT/React

[react] react Framer-motion λ¦¬μ•‘νŠΈ ν”„λ ˆμ΄λ¨Έ ν™œμš©ν•˜κΈ° (μ• λ‹ˆλ©”μ΄μ…˜μ„ κ°„νŽΈν•˜κ²Œ!)

ITyranno 2024. 1. 10. 16:21
728x90
λ°˜μ‘ν˜•

 

 

 

 

 

 

 

 

ν”„λ‘œκ·Έλž˜λ° 세계λ₯Ό νƒκ΅¬ν•©μ‹œλ‹€.

 

 

 

 

 

react Framer-motion λ¦¬μ•‘νŠΈ ν”„λ ˆμ΄λ¨Έ λͺ¨μ…˜ ν™œμš©ν•˜κΈ°

 

 

 

React Framer Motion은 μ£Όλ‘œ λ‹€μŒκ³Ό κ°™μ€ μ—­ν• μ„ ν•©λ‹ˆλ‹€:

μ• λ‹ˆλ©”μ΄μ…˜ μ œμ–΄: μ‚¬μš©μžκ°€ μ •μ˜ν•œ μ»΄ν¬λ„ŒνŠΈλ‚˜ DOM μš”μ†Œλ₯Ό μ• λ‹ˆλ©”μ΄μ…˜ν™”ν•  μˆ˜ μžˆμŠ΅λ‹ˆλ‹€. μ›€μ§μž„, ν¬κΈ° μ‘°μ ˆ, νšŒμ „ λ“± λ‹€μ–‘ν•œ μ• λ‹ˆλ©”μ΄μ…˜ νš¨κ³Όλ₯Ό κ΅¬ν˜„ν•  μˆ˜ μžˆμŠ΅λ‹ˆλ‹€.

제슀처 μ²˜λ¦¬: ν„°μΉ˜, ν΄λ¦­ λ“±μ˜ μ œμŠ€μ²˜ μ΄λ²€νŠΈλ₯Ό κ°μ§€ν•˜κ³  μ΄μ— λ”°λ₯Έ μ• λ‹ˆλ©”μ΄μ…˜μ„ μ‰½κ²Œ μΆ”κ°€ν•  μˆ˜ μžˆμŠ΅λ‹ˆλ‹€.

μ»΄ν¬λ„ŒνŠΈ κ°„ ν†΅μ‹ : λ‹€μ–‘ν•œ μ»΄ν¬λ„ŒνŠΈ κ°„μ˜ ν†΅μ‹ μ„ μ΄‰μ§„ν•˜λ©°, μ• λ‹ˆλ©”μ΄μ…˜μ„ ν†΅ν•œ μ‚¬μš©μž κ²½ν—˜ ν–₯상에 κΈ°μ—¬ν•©λ‹ˆλ‹€.

 

 

 

 

 

 

react Framer-motion λ¦¬μ•‘νŠΈ ν”„λ ˆμ΄λ¨Έ λͺ¨μ…˜ κ΅¬ν˜„ μ˜ˆμ‹œ

 

 

κ΅¬ν˜„ μ˜ˆμ‹œ ν™”λ©΄μž…λ‹ˆλ‹€.

 

밑쀄 효과, 마우슀 hover μ‹œ boxκ°€ μ»€μ§€λŠ” 효과, λ²„νŠΌμ΄ λ‚˜νƒ€λ‚˜λŠ” 효과λ₯Ό μ‚¬μš©ν–ˆμŠ΅λ‹ˆλ‹€.

 

 

 

 

 

react Framer-motion λ¦¬μ•‘νŠΈ ν”„λ ˆμ΄λ¨Έ λͺ¨μ…˜ ν™œμš© 방법

 

 

1. 곡식 μ‚¬μ΄νŠΈ

 

λ‹€μ–‘ν•œ νš¨κ³Όμ™€ μ‚¬μ΄νŠΈλŠ” μ•„λž˜ μ‚¬μ΄νŠΈ μ°Έκ³  λ°”λžλ‹ˆλ‹€.

 

https://www.framer.com/motion/

 

Documentation | Framer for Developers

An open source, production-ready motion library for React on the web.

www.framer.com

 

 

 

1. 제슀처 μ΄λ²€νŠΈμ™€ νŠΈλžœμ§€μ…˜: whileHover, whileTap λ“±μ˜ 제슀처 κ΄€λ ¨ 이벀트λ₯Ό 톡해 μ‚¬μš©μž μƒν˜Έ μž‘μš©μ— λ°˜μ‘ν•˜λ©° λΆ€λ“œλŸ¬μš΄ νŠΈλžœμ§€μ…˜μ„ μ œκ³΅ν•©λ‹ˆλ‹€.

 

2. ν”„λ ˆμž„-별 μ• λ‹ˆλ©”μ΄μ…˜: animate μ†μ„±μ„ ν†΅ν•΄ νŠΉμ • ν”„λ ˆμž„μ—μ„œμ˜ μ†μ„±μ„ μ§€μ •ν•˜κ³ , λΆ€λ“œλŸ½κ²Œ μ „ν™˜ν•  μˆ˜ μžˆμŠ΅λ‹ˆλ‹€.

 

 

 

2. μ„€μΉ˜

 

μ•„λž˜ λͺ…λ Ήμ–΄λ₯Ό μž…λ ₯ν•˜λ©΄ μ„€μΉ˜ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

npm install framer-motion

 

 

 

3. μ‚¬μš© 방법

 

motion을 μž„ν¬νŠΈν•˜κ³  motion.divλ₯Ό μž‘μ„±ν•˜μ—¬ μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

 

import { motion } from 'framer-motion'

<motion.div animate={{ scale: 0.7 }} />

 

 

 

4. μž‘μ„± μ½”λ“œ

 

μ˜ˆμ‹œ 화면에 λŒ€ν•œ μž‘μ„± μ½”λ“œμž…λ‹ˆλ‹€.

 

 

 

import style from './Main.module.css';
import { motion } from "framer-motion";
import { Link } from 'react-router-dom';
import { useState } from 'react';

function Main() {
    // λ²„νŠΌ μ΄λ―Έμ§€μ˜ μ• λ‹ˆλ©”μ΄μ…˜ μƒνƒœλ₯Ό μ œμ–΄ν•˜κΈ° μœ„ν•œ state
    const [isHovered, setIsHovered] = useState(false);

    // λ²„νŠΌ λ°•μŠ€μ˜ μ• λ‹ˆλ©”μ΄μ…˜ μƒνƒœλ₯Ό μ •μ˜ν•©λ‹ˆλ‹€.
    const buttonBoxVariants = {
        hover: { scale: 1.1 },
        tap: { scale: 0.9 }
    };

    // λ²„νŠΌ μ΄λ―Έμ§€μ˜ μ• λ‹ˆλ©”μ΄μ…˜ μƒνƒœλ₯Ό μ •μ˜ν•©λ‹ˆλ‹€.
    const buttonIconVariants = {
        hidden: { x: -30, opacity: 0 }, // μ™Όμͺ½μ— μˆ¨κ²¨μ§„ μƒνƒœ
        visible: { x: 0, opacity: 1 } // μ›λž˜ μœ„μΉ˜μ— λ‚˜νƒ€λ‚œ μƒνƒœ
    };

    return (
        <div className={style.mainpage}>
            <div className={style.main}>
                <div className={style.main_text}>
                    <h1 className={style.main_text1}><span className={style.highlight1}>λ§›</span>μ§‘,</h1>
                    <h1 className={style.main_text2}><span className={style.highlight2}>λ“±μ‚°</span>둜,</h1>
                    <h1 className={style.main_text2}><span className={style.highlight1}>산악기상정보</span>λ₯Ό</h1>
                    <h1 className={style.main_text3}>
                        <span>ν•œ 번의 κ²€μƒ‰μœΌλ‘œ ν™•μΈν•˜μ„Έμš”.</span>
                        <motion.span
                            className={style.underline}
                            initial={{ width: 0 }}
                            animate={{ width: "100%" }}
                            transition={{
                                repeat: Infinity,
                                repeatType: "reverse",
                                duration: 3
                            }}
                        />
                    </h1>
                </div>
                <div className={style.main_box}>
                    <Link className={style.main_map} to="/map">
                        <motion.div
                            className={style.box}
                            variants={buttonBoxVariants}
                            whileHover="hover"
                            whileTap="tap"
                            onHoverStart={() => setIsHovered(true)}
                            onHoverEnd={() => setIsHovered(false)}
                        >
                            <div className={style.main_mapimg}>
                                <img src={`${process.env.PUBLIC_URL}/img/mapimg.png`} alt="mapimg" className={style.mapimg} />
                            </div>
                            {/* ν…μŠ€νŠΈ λΆ€λΆ„ */}
                            <div className={style.box_text1}>
                                λ“±μ‚° 정보 κ²€μƒ‰ν•˜λŸ¬ κ°€κΈ°
                            </div>
                            {/* 이미지 λΆ€λΆ„ */}
                            <motion.img
                                src={`${process.env.PUBLIC_URL}/img/button.svg`}
                                alt="λ²„νŠΌ"
                                className={style.buttonIcon}
                                variants={buttonIconVariants}
                                initial="hidden"
                                animate={isHovered ? "visible" : "hidden"}
                                transition={{ duration: 0.3 }}
                            />
                        </motion.div>
                    </Link>
                </div>
            </div>
        </div>
    );
}

export default Main;

 

 

 

 

 

 

μœ„μ™€ 같은 λ°©μ‹μœΌλ‘œ reactμ—μ„œ framer-motion을 μ‚¬μš©ν•˜μ—¬ μ• λ‹ˆλ©”μ΄μ…˜μ„ 효과적으둜 κ΅¬ν˜„ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

 

 

728x90
λ°˜μ‘ν˜•