Skip to content

Commit e25760c

Browse files
authored
feat(Poe): add animation when component is visible (#132)
feat(deps): install @vueuse/nuxt package feat(nuxt): add @vueuse/nuxt module to nuxt config chore(deps): update pnpm.lock file with @vueuse/nuxt package The changes made in this commit are: 1. Added a new `@vueuse/nuxt` package to the project dependencies. 2. Installed the `@vueuse/nuxt` module in the `nuxt.config.ts` file. 3. Updated the `pnpm-lock.yaml` file with the new `@vueuse/nuxt` package and its dependencies. 4. In the `components/custom/Poe.vue` file, added a new ref `elePoe` to the root element and used the `useElementVisibility` hook from `@vueuse/core` to detect when the component becomes visible. 5. Added a new class `animate` that is applied to the component when it becomes visible, which triggers the animation on the `.major` and `.poe div` elements. 6. Paused the animation initially, and started it when the component becomes visible. These changes were made to improve the user experience by adding an animation effect to the Poe component when it comes into view, making the content more engaging and visually appealing.
1 parent 48750d3 commit e25760c

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

components/custom/Poe.vue

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
<script setup lang="ts">
2+
import { useElementVisibility } from '@vueuse/core'
23
4+
const elePoe = ref<HTMLElement | null>(null)
5+
const targetIsVisible = useElementVisibility(elePoe)
36
</script>
47

58
<template>
6-
<div class="body pt-12 h-screen pb-12">
7-
<div class="relative flex flex-row items-center justify-center gap-2 h-full">
9+
<div
10+
ref="elePoe"
11+
class="body pt-12 h-screen pb-12"
12+
>
13+
<div
14+
:class="{ animate: targetIsVisible }"
15+
class="relative flex flex-row items-center justify-center gap-2 h-full"
16+
>
817
<div class="major text-7xl text-center font-bold tracking-tight text-black">
918
谁怕?一蓑烟雨任平生
1019
</div>
@@ -32,6 +41,7 @@
3241
.major {
3342
@apply opacity-0;
3443
animation: fadeIn 1.5s ease-in-out 3.5s forwards;
44+
animation-play-state: paused !important;
3545
}
3646
3747
.poe {
@@ -40,10 +50,15 @@
4050
4151
.poe div {
4252
@apply block m-3 z-10 opacity-20 hover:opacity-100 duration-200;
43-
animation-fill-mode: forwards;
53+
animation-play-state: paused !important;
4454
white-space: nowrap;
4555
}
4656
57+
.animate .major,
58+
.animate .poe div {
59+
animation-play-state: running !important;
60+
}
61+
4762
@keyframes fadeIn {
4863
0% {
4964
opacity: 0;

nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export default defineNuxtConfig({
6262
'@nuxtjs/web-vitals',
6363
'nuxt-gtag',
6464
'@nuxt/eslint',
65+
'@vueuse/nuxt',
6566
],
6667

6768
eslint: {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@trpc/client": "^10.45.2",
2626
"@trpc/server": "^10.45.2",
2727
"@vitest/coverage-v8": "^1.4.0",
28+
"@vueuse/nuxt": "^10.9.0",
2829
"class-variance-authority": "^0.7.0",
2930
"clsx": "^2.1.1",
3031
"consola": "^3.2.3",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)