Skip to content

Commit 3f5f60c

Browse files
committed
feat: mp3 dynamically set css variables
1 parent 1a55402 commit 3f5f60c

5 files changed

Lines changed: 75 additions & 1 deletion

File tree

2.04 MB
Binary file not shown.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, { useRef, useState } from 'react'
2+
import styles from './index.module.less'
3+
import music from '@assets/audio/heart-of-the-sea.mp3'
4+
const SoundBar = () => {
5+
const [isPlaying, setIsPlaying] = useState(false)
6+
const audioRef = useRef(null)
7+
const togglePlay = () => {
8+
if (isPlaying) {
9+
audioRef.current.pause()
10+
} else {
11+
audioRef.current.play()
12+
}
13+
setIsPlaying(!isPlaying)
14+
}
15+
16+
return (
17+
<>
18+
<span className={styles.audio} onClick={togglePlay}>
19+
{Array.from({ length: 5 }, () => ({ id: Math.random() })).map((item, index) => (
20+
<span
21+
key={item.id}
22+
style={{ '--i': index, '--state': isPlaying ? 'running' : 'paused' }}
23+
className={styles.line}
24+
/>
25+
))}
26+
</span>
27+
<audio src={music} ref={audioRef} loop>
28+
<track kind="captions" default />
29+
</audio>
30+
</>
31+
)
32+
}
33+
34+
export default SoundBar
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.audio {
2+
--i: 0;
3+
--state: paused;
4+
5+
display: flex;
6+
flex-direction: row;
7+
justify-content: center;
8+
align-items: center;
9+
width: 100%;
10+
cursor: pointer;
11+
z-index: 3;
12+
position: relative;
13+
14+
.line {
15+
background: #00ff7f;
16+
animation: play 1s ease infinite;
17+
animation-delay: calc(var(--i) * 0.1s);
18+
animation-play-state: var(--state);
19+
height: 10px;
20+
width: 2px;
21+
margin: 0 1px;
22+
}
23+
}
24+
25+
@keyframes play {
26+
0% {
27+
transform: scaleY(1);
28+
}
29+
30+
50% {
31+
transform: scaleY(1.5);
32+
}
33+
34+
100% {
35+
transform: scaleY(1);
36+
}
37+
}

src/pages/layout/proHeader/index.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import LanguageSwitcher from '@stateless/LanguageSwitcher'
1111
// import LightSvg from '@assets/svg/light.svg'
1212
// import DarkSvg from '@assets/svg/dark.svg'
1313

14+
import SoundBar from '@stateless/SoundBar'
15+
1416
import { useProThemeContext } from '@theme/hooks'
1517

1618
import PrimaryNav from '../primaryNav'
@@ -84,6 +86,7 @@ const ProHeader = () => {
8486
</div>
8587
<div className={styles.headerRight}>
8688
<Space direction="horizontal" style={{ cursor: 'pointer', paddingRight: 8 }}>
89+
<SoundBar />
8790
<Switch
8891
// checkedChildren={<Icon component={LightSvg} />}
8992
// unCheckedChildren={<Icon component={DarkSvg} />}

webpack/webpack.common.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ const config = {
199199
],
200200
},
201201
{
202-
test: /\.(png|jpe?g|gif|webp|eot|ttf|woff|woff2|mp4|mkv|pdf)$/i,
202+
test: /\.(png|jpe?g|gif|webp|eot|ttf|woff|woff2|mp4|mp3|mkv|pdf)$/i,
203203
type: 'asset',
204204
parser: {
205205
// Conditions for converting to base64

0 commit comments

Comments
 (0)