-
Notifications
You must be signed in to change notification settings - Fork 0
/
PostItem.vue
95 lines (87 loc) · 1.93 KB
/
PostItem.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<script lang="ts" setup>
import type { ContentData } from "vitepress";
import { useRouter, withBase } from "vitepress";
import { onMounted, ref } from "vue";
defineProps<{ post: ContentData }>();
const router = useRouter();
function changeRoute(to: string) {
if (!document.startViewTransition) {
router.go(to);
return;
}
// to avoid animation confict with the global transition
const VPContentEl = document.querySelector(".VPContent")! as HTMLElement;
VPContentEl.style.setProperty("view-transition-name", "route");
const transition = document.startViewTransition(async () => {
await router.go(to);
});
transition.finished.then(() => {
VPContentEl.style.removeProperty("view-transition-name");
});
}
const viewTransitionsEnabled = ref(false);
onMounted(() => {
viewTransitionsEnabled.value = "startViewTransition" in document;
});
</script>
<template>
<a
class="post-title"
:class="viewTransitionsEnabled && 'vp-raw'"
:href="withBase(post.url)"
@click.prevent="changeRoute(post.url)"
>
{{ post.frontmatter.title }}
</a>
</template>
<style scoped>
.post-title {
overflow-x: hidden;
text-wrap: nowrap;
text-overflow: ellipsis;
color: var(--sr-c-text);
font-weight: normal;
padding: 0 1rem;
transition: all 0.5s ease;
&:hover {
color: var(--sr-c-text-hover);
font-weight: bold;
}
}
</style>
<style>
@keyframes shift-to-left {
0% {
opacity: 1;
transform: translateX(0);
}
50% {
opacity: 0;
transform: translateX(-100px);
}
100% {
opacity: 0;
transform: translateX(-100px);
}
}
@keyframes push-from-right {
0% {
opacity: 0;
transform: translateX(100px);
}
50% {
opacity: 0;
transform: translateX(100px);
}
100% {
opacity: 1;
transform: translateX(0);
}
}
::view-transition-old(route) {
animation: shift-to-left 0.6s linear;
}
::view-transition-new(route) {
animation: push-from-right 0.6s linear;
}
</style>