Skip to content

Commit ec67659

Browse files
committed
feat: animation text
1 parent 12f97b5 commit ec67659

5 files changed

Lines changed: 115 additions & 7 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React, { useEffect, useState } from 'react'
2+
3+
import styles from './index.module.less'
4+
5+
const AnimText = ({ animText = '' }) => {
6+
const arrText = animText.split('') || []
7+
const [letterClass, setLetterClass] = useState('text-animate')
8+
9+
useEffect(() => {
10+
setTimeout(() => {
11+
setLetterClass('text-animate-hover')
12+
}, 3000)
13+
}, [])
14+
15+
return (
16+
<span>
17+
{arrText.map((item, index) => (
18+
<span key={item + index} style={{ '--delay': index + 1 }} className={styles[letterClass]}>
19+
{item}
20+
</span>
21+
))}
22+
</span>
23+
)
24+
}
25+
26+
export default AnimText
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
.text-animate {
2+
display: inline-block;
3+
opacity: 0;
4+
animation: bounce-in;
5+
animation-duration: 1s;
6+
animation-delay: 1s;
7+
animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
8+
animation-fill-mode: forwards;
9+
min-width: 10px;
10+
}
11+
12+
.text-animate-hover {
13+
--delay: 0;
14+
15+
min-width: 10px;
16+
display: inline-block;
17+
animation: rubber-band 1s;
18+
animation-fill-mode: both;
19+
animation-delay: var(--delay) s;
20+
21+
&:hover {
22+
animation: none;
23+
color: #ff4500;
24+
}
25+
}
26+
27+
@keyframes bounce-in {
28+
0% {
29+
opacity: 0;
30+
transform: scale3d(0.3, 0.3, 0.3);
31+
}
32+
33+
20% {
34+
transform: scale3d(1.1, 1.1, 1.1);
35+
}
36+
37+
40% {
38+
transform: scale3d(0.9, 0.9, 0.9);
39+
}
40+
41+
60% {
42+
opacity: 1;
43+
transform: scale3d(1.03, 1.03, 1.03);
44+
}
45+
46+
80% {
47+
transform: scale3d(0.97, 0.97, 0.97);
48+
}
49+
50+
100% {
51+
opacity: 1;
52+
transform: scale3d(1, 1, 1);
53+
}
54+
}
55+
56+
@keyframes rubber-band {
57+
0% {
58+
transform: scale3d(1, 1, 1);
59+
}
60+
61+
30% {
62+
transform: scale3d(1.25, 0.75, 1);
63+
}
64+
65+
40% {
66+
transform: scale3d(0.75, 1.25, 1);
67+
}
68+
69+
50% {
70+
transform: scale3d(1.15, 0.85, 1);
71+
}
72+
73+
65% {
74+
transform: scale3d(0.95, 1.05, 1);
75+
}
76+
77+
75% {
78+
transform: scale3d(1.05, 0.95, 1);
79+
}
80+
81+
100% {
82+
transform: scale3d(1, 1, 1);
83+
}
84+
}

src/components/stateless/StarBackground/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react'
1+
import React, { useState } from 'react'
22
import styles from './index.module.less'
33
// 生成随机阴影值的函数
44
const generateBoxShadow = (n) => {

src/pages/home/index.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import DottedStepper from '@stateless/DottedStepper'
6565
import FlipWords from '@stateless/FlipWords'
6666
import BorderBeam from '@stateless/BorderBeam'
6767
import AutoSlider from '@stateless/AutoSlider'
68+
import AnimText from '@stateless/AnimText'
6869
import firstImage from '@assets/images/88-300x160.jpg'
6970
import secondImage from '@assets/images/2-300x160.jpg'
7071

@@ -327,6 +328,9 @@ const Home = () => {
327328
<section style={{ margin: '20px 0', fontSize: 20 }}>
328329
<MultiDirectionSlide textLeft="逐光前行,奔赴新程;" textRight="千山过尽,万里星辰!" />
329330
</section>
331+
<section style={{ margin: '20px 0', fontSize: 20 }}>
332+
<AnimText animText="逐光前行,奔赴新程;千山过尽,万里星辰!" />
333+
</section>
330334
<section style={{ marginBottom: 15, fontSize: 20, overflow: 'hidden' }}>
331335
This is something
332336
<SlideText text={['amazing', 'new', 'wonderful', 'beautiful', 'smart']} />

src/styles/reset.css

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@
9696
}
9797
}
9898

99-
/* body {
100-
color: var(--foreground);
101-
background: var(--background);
102-
font-family: Arial, Helvetica, sans-serif;
103-
} */
104-
10599
html,
106100
body {
107101
height: 100%;

0 commit comments

Comments
 (0)