Skip to content

Commit ab9debc

Browse files
committed
feat: long time no see
1 parent 495c6a9 commit ab9debc

File tree

7 files changed

+120
-17
lines changed

7 files changed

+120
-17
lines changed

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<meta charset="UTF-8">
55
<link rel="icon" href="/favicon.ico">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<title>MMT typeface</title>
7+
<title>沐目体</title>
88
<meta name="keywords" content="MMT typeface, 沐目体, 手写体, 中文字体">
9-
<meta name="description" content="MMT typeface is a hand-drawn Chinese font that is free for personal use.">
9+
<meta name="description" content="沐目体字体是一种手绘的中文字体,可供个人免费使用。">
1010
</head>
1111
<body>
1212
<div id="app"></div>

src/App.vue

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,39 @@ import SectionPreview from './components/SectionPreview.vue'
66
</script>
77

88
<template>
9-
<SectionCover />
10-
<SectionPreview />
11-
<SectionMusic />
9+
<main class="main-container">
10+
<SectionCover />
11+
<SectionPreview />
12+
<SectionMusic />
13+
</main>
1214
<Footer />
1315
</template>
1416

1517
<style scoped>
18+
@media (min-width: 1024px) {
19+
.main-container {
20+
display: grid;
21+
grid-template-rows: 1fr auto auto;
22+
margin-block-start: 200px;
23+
box-shadow: 0 0 20px var(--color-box-shadow, rgba(0, 0, 0, 0.2));
24+
border-radius: var(--border-radius);
25+
}
26+
section {
27+
&:first-of-type {
28+
border-top-left-radius: var(--border-radius);
29+
border-top-right-radius: var(--border-radius);
30+
}
31+
&:last-of-type {
32+
border-bottom-left-radius: var(--border-radius);
33+
border-bottom-right-radius: var(--border-radius);
34+
}
35+
}
36+
}
37+
@media (prefers-color-scheme: dark) {
38+
.main-container {
39+
--color-box-shadow: rgba(255, 255, 255, 0.2);
40+
}
41+
}
1642
section {
1743
border: 2px solid var(--color-border);
1844
&:not(:last-of-type) {

src/assets/base.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
--color-text: #000;;
44
--color-background: #ffffff;
55
--color-border: rgba(60, 60, 60, 0.12);
6+
--border-radius: 0.75rem;
67
}
78

89
@media (prefers-color-scheme: dark) {

src/assets/main.css

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
}
1616

1717
#app {
18-
display: grid;
19-
grid-template-rows: 1fr auto auto;
2018
max-width: 1000px;
2119
}
2220
}

src/components/SectionCover.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
aria-label="View source on GitHub"
99
>
1010
<svg
11-
width="80"
12-
height="80"
11+
width="50"
12+
height="50"
1313
viewBox="0 0 250 250"
1414
aria-hidden="true"
1515
>
@@ -23,6 +23,7 @@
2323

2424
<style scoped>
2525
.section-cover {
26+
position: relative;
2627
.manuscript {
2728
width: 100%;
2829
height: auto;
@@ -77,6 +78,15 @@
7778
}
7879
}
7980
81+
@media (min-width: 1024px) {
82+
.section-cover {
83+
.manuscript {
84+
border-top-left-radius: var(--border-radius);
85+
border-top-right-radius: var(--border-radius);
86+
}
87+
}
88+
}
89+
8090
@media (prefers-color-scheme: dark) {
8191
.github-corner {
8292
--github-corner-fill: #fff;

src/components/SectionMusic.vue

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const defaultComment: Comment = {
2323
avatarUrl: '',
2424
}
2525
const comment = ref<Comment>(defaultComment)
26+
const TIME_OUT = 30
27+
const timer = ref<ReturnType<typeof setInterval> | null>(null)
2628
2729
function getRandomComment() {
2830
loading.value = true
@@ -50,14 +52,37 @@ function getRandomComment() {
5052
})
5153
}
5254
53-
onMounted(() => {
55+
function refresh() {
5456
getRandomComment()
57+
if (timer.value) {
58+
clearInterval(timer.value)
59+
}
60+
timer.value = setInterval(() => {
61+
getRandomComment()
62+
}, TIME_OUT * 1000)
63+
}
64+
65+
onMounted(() => {
66+
const observer = new IntersectionObserver((entries) => {
67+
entries.forEach((entry) => {
68+
if (entry.isIntersecting) {
69+
// 进入视口时开始获取评论
70+
refresh()
71+
// 取消观察
72+
observer.disconnect()
73+
}
74+
})
75+
}, { threshold: 0.1 })
76+
const target = document.querySelector('.section-music')
77+
if (target) {
78+
observer.observe(target)
79+
}
5580
})
5681
</script>
5782

5883
<template>
5984
<section class="section-music">
60-
<div v-if="!loading" class="comment-163" title="随机下一条" @click="getRandomComment">
85+
<div v-if="!loading" class="comment-163" title="随机下一条" @click="refresh">
6186
<span class="pic-backdrop" :style="comment.picUrl ? `background-image: url(${comment.picUrl});` : ''" />
6287
<div class="commentator">
6388
<img
@@ -98,7 +123,7 @@ onMounted(() => {
98123
position: relative;
99124
border: 1px solid #f5f5f5;
100125
padding: 0.75em;
101-
border-radius: 0.75rem;
126+
border-radius: var(--border-radius);
102127
color: var(--color-comment, #272626);
103128
cursor: pointer;
104129
height: 100%;
@@ -113,7 +138,7 @@ onMounted(() => {
113138
filter: blur(10px);
114139
background-size: cover;
115140
background-position: center;
116-
border-radius: 0.75rem;
141+
border-radius: var(--border-radius);
117142
z-index: -1;
118143
opacity: 0.75;
119144
}

src/components/SectionPreview.vue

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script setup lang="ts">
2-
import { computed, ref } from 'vue'
2+
import { computed, onMounted, ref } from 'vue'
33
44
const message = ref<string>('')
55
const fontSize = ref<number>(24)
66
const fontWeight = ref<number>(400)
77
const fontWeightOptions = [400, 500, 600, 700, 800, 900]
8+
const defaultMessage = ref<string>('')
89
910
const style = computed(() => {
1011
const size = fontSize.value < 20 ? 20 : fontSize.value
@@ -14,13 +15,54 @@ const style = computed(() => {
1415
}
1516
})
1617
18+
function typeIt() {
19+
const text = '沐目之,湘也。\n\n字字珠玑,见字如面。'
20+
let index = 0
21+
let interval: ReturnType<typeof setInterval> | undefined
22+
const _typeIt = (observer: IntersectionObserver) => {
23+
interval = setInterval(() => {
24+
defaultMessage.value += text[index]
25+
index++
26+
if (index >= text.length) {
27+
// 停止定时器
28+
clearInterval(interval)
29+
// 取消观察
30+
observer.disconnect()
31+
}
32+
}, 100)
33+
}
34+
const observer = new IntersectionObserver((entries: IntersectionObserverEntry[]) => {
35+
entries.forEach((entry: IntersectionObserverEntry) => {
36+
// 如果元素在视口中可见,触发打字效果
37+
if (entry.isIntersecting) {
38+
_typeIt(observer)
39+
}
40+
else {
41+
clearInterval(interval)
42+
}
43+
})
44+
}, { threshold: 0.1 })
45+
const target = document.querySelector('.live-content')
46+
if (target) {
47+
observer.observe(target)
48+
}
49+
}
50+
51+
onMounted(() => {
52+
typeIt()
53+
})
54+
1755
if (window.innerWidth < 768) {
1856
fontSize.value = 20
1957
}
2058
2159
// ————“沐目之,湘也。”
2260
// 取字于大学时初恋的名字,这个字体也是为她而写。
61+
// 从下笔到停笔,从开始到结束,它见证了我们稚嫩到成熟。
2362
// 沐目体和红人馆的那首《最甜情歌》有着类似的遭遇。
63+
// 故事的开头极具温柔,但结局不尽人意。
64+
// 那些忘不掉的人和事,岁月都已替我轻描淡写。
65+
//
2466
// 事隔经年,淡然写下。
2567
</script>
2668

@@ -46,7 +88,7 @@ if (window.innerWidth < 768) {
4688
</header>
4789
<main>
4890
<p class="live-content">
49-
{{ message || '「沐目之,湘也」\n 从下笔到停笔,从开始到结束,沐目体见证了我们稚嫩到成熟。\n故事的开头往往极具温柔,但结局常常不尽人意。\n那些忘不掉的人和事,岁月都已替我轻描淡写。' }}
91+
{{ message || defaultMessage }}
5092
</p>
5193
<textarea v-model="message" class="live-textarea" placeholder="中文测试器,你可以在这里写任何字来测试字体!" />
5294
</main>
@@ -97,7 +139,7 @@ if (window.innerWidth < 768) {
97139
.live-content {
98140
font-family: MMT;
99141
font-weight: var(--live-font-weight);
100-
line-height: 1.25;
142+
line-height: 26px;
101143
width: 50%;
102144
min-height: 120px;
103145
max-height: 400px;
@@ -107,11 +149,12 @@ if (window.innerWidth < 768) {
107149
linear-gradient(1turn, var(--color-border) 3%, transparent 0);
108150
background-size: 24px 24px;
109151
background-position: center;
152+
white-space: pre-wrap;
110153
}
111154
.live-textarea {
112155
width: 50%;
113156
padding: 0.5rem;
114-
border-radius: 0.75rem;
157+
border-radius: var(--border-radius);
115158
resize: vertical;
116159
border: 1px solid var(--color-border);
117160
background-color: var(--color-background);

0 commit comments

Comments
 (0)