적용 방법
- tailwind.confing.ts에
keyframes, animation 정의
import { transform } from "next/dist/build/swc/generated-native";
import type { Config } from "tailwindcss";
export default {
darkMode: ["class"],
content: [
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
backgroundImage: {
"home-img": "url('/images/home-img.jpg')",
},
colors: {
background: "hsl(var(--background))",
foreground: "hsl(var(--foreground))",
....,
keyframes: {
appear: {
from: {
opacity: "0",
},
to: {
opacity: "1",
},
},
slide: {
from: {
transform: "translateX(-100%)",
},
to: {
transform: "translateX(0%)",
},
},
},
animation: {
appear: "appear .65s linear",
slide: "slide 750ms ease-in-out",
},
},
},
plugins: [require("tailwindcss-animate")],
} satisfies Config;
animation을 관련 부분만 따로 보면
css에서 keyframes로 애니메이션을 정의하고
animation 속성으로 적용하는 것과 같은 방식이다.
keyframes: {
appear: { --------------> 이름은 본인이 정하면 된다.
from: { --------------> from/to 또는 0%/25%/50%...로 설정 가능하다.
opacity: "0",
},
to: {
opacity: "1",
},
},
slide: {
from: {
transform: "translateX(-100%)",
},
to: {
transform: "translateX(0%)",
},
},
},
animation: { -------------> animation 설정
appear: "appear .65s linear",
slide: "slide 750ms ease-in-out",
},
사용 시
className에 "animate-정의한 애니메이션 이름" 으로 요소에 animation을 적용.
import React from "react";
export default async function Template({
children,
}: {
children: React.ReactNode;
}) {
return <div className="animate-appear">{children}</div>;
}