valaxy博客全局美化教程(六)

本系列教程共十篇

话不多说,先看效果

页面下滑时信封自动展开,上划自动闭合,可以自己换图片,但是尺寸要一样哈,由于涉及到图床,大家尽量只下载图片,不要直接使用站长的链接,因为站长不能保证什么时候就失效了
给出所有图片的图床链接:

1
2
3
4
https://pic1.imgdb.cn/item/6a26e5483c9809430d376f88.png
https://pic1.imgdb.cn/item/6a26e5483c9809430d376f87.png
https://pic1.imgdb.cn/item/6a26e5483c9809430d376f85.png
https://pic1.imgdb.cn/item/6a26e5483c9809430d376f86.png

从上到下分别是信纸、顶部信封、底部信封和横条,下面链接和这里一样,大家最好修改一下,测试用着可以,不要生产环境使用哦

新增文件

新增文件咯,只有一个文件,有点长哦
新增文件components\layouts\SakuraCommentLayout.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
<script setup lang="ts">
import { useSiteConfig } from 'valaxy'
import { computed, onMounted, onUnmounted, ref } from 'vue'

const siteConfig = useSiteConfig()
const authorName = computed(() => siteConfig.value.author?.name || '站长')

const isOpened = ref(false)
const formWrapRef = ref<HTMLElement>()

const envelopeConfig = {
images: {
cover: 'https://pic1.imgdb.cn/item/6a26e5483c9809430d376f88.png',
line: 'https://pic1.imgdb.cn/item/6a26e5483c9809430d376f86.png',
beforeimg: 'https://pic1.imgdb.cn/item/6a26e5483c9809430d376f85.png',
afterimg: 'https://pic1.imgdb.cn/item/6a26e5483c9809430d376f87.png',
},
wrapHeight: 447,
openHeight: 1050,
openOffset: -200,
/** 滚回页面顶部时闭合(px) */
scrollCloseTop: 80,
}

const message = [
'本站有哪些做得好或者不好的地方?',
'或者你有什么改进的建议?',
'又或者你有什么具体的问题需要咨询?',
'都可以在下方评论区留言哦~~~',
]

const bottomText = '小站站长亲自为您服务!'

let scrollRaf: number | undefined

function getScrollTop() {
return window.pageYOffset
|| document.documentElement.scrollTop
|| document.body.scrollTop
|| 0
}

function openEnvelope() {
isOpened.value = true
}

function closeEnvelope() {
isOpened.value = false
}

function handleEnvelopeClick() {
if (!isOpened.value)
openEnvelope()
}

function isEnvelopeFullyVisible() {
if (!formWrapRef.value || isOpened.value)
return false

const rect = formWrapRef.value.getBoundingClientRect()
const viewportHeight = window.innerHeight

// 桌面信封隐藏(移动端)时不触发
if (rect.width === 0 || rect.height === 0)
return false

// 信封(闭合高度)完整出现在视口内时展开
return rect.top >= 0 && rect.bottom <= viewportHeight + 1
}

function updateEnvelopeByScroll() {
if (isEnvelopeFullyVisible()) {
openEnvelope()
return
}

if (isOpened.value && getScrollTop() <= envelopeConfig.scrollCloseTop)
closeEnvelope()
}

function handleScroll() {
if (scrollRaf)
return

scrollRaf = requestAnimationFrame(() => {
scrollRaf = undefined
updateEnvelopeByScroll()
})
}

onMounted(() => {
updateEnvelopeByScroll()
window.addEventListener('scroll', handleScroll, { passive: true })
window.addEventListener('resize', handleScroll, { passive: true })
})

onUnmounted(() => {
if (scrollRaf)
cancelAnimationFrame(scrollRaf)
window.removeEventListener('scroll', handleScroll)
window.removeEventListener('resize', handleScroll)
})
</script>

<template>
<SakuraPage class="sakura-comment-page">
<template #content>
<RouterView v-slot="{ Component }">
<component :is="Component">
<template #main-content>
<div id="envelope-maincontent" class="envelope-maincontent">
<div
id="form-wrap"
ref="formWrapRef"
class="form-wrap envelope-desktop"
:class="{ opened: isOpened }"
:style="{
'--wrap-height': `${envelopeConfig.wrapHeight}px`,
'--open-height': `${envelopeConfig.openHeight}px`,
'--open-offset': `${envelopeConfig.openOffset}px`,
}"
@click="handleEnvelopeClick"
>
<img
id="beforeimg"
class="beforeimg"
:src="envelopeConfig.images.beforeimg"
alt="信封背景"
loading="lazy"
>

<div id="envelope" class="envelope">
<div class="formmain">
<img
class="headerimg"
:src="envelopeConfig.images.cover"
alt="信笺封面"
loading="lazy"
>

<div class="comments-main">
<h3 class="title3">
✨来自{{ authorName }}的留言:
</h3>

<div class="comments">
<p
v-for="(msg, index) in message"
:key="index"
>
{{ msg }}
</p>
</div>

<div class="bottomcontent">
<img
class="bottomimg"
:src="envelopeConfig.images.line"
alt="信笺底部装饰"
loading="lazy"
>
</div>

<p class="bottomhr">
{{ bottomText }}
</p>
</div>
</div>
</div>

<img
id="afterimg"
class="afterimg"
:src="envelopeConfig.images.afterimg"
alt="信封前景"
loading="lazy"
>
</div>

<!-- 移动端:无信封图片,仅展示信笺 -->
<div class="envelope-mobile">
<div class="formmain">
<img
class="headerimg"
:src="envelopeConfig.images.cover"
alt="信笺封面"
loading="lazy"
>

<div class="comments-main">
<h3 class="title3">
✨来自{{ authorName }}的留言:
</h3>

<div class="comments">
<p
v-for="(msg, index) in message"
:key="index"
>
{{ msg }}
</p>
</div>

<div class="bottomcontent">
<img
class="bottomimg"
:src="envelopeConfig.images.line"
alt="信笺底部装饰"
loading="lazy"
>
</div>

<p class="bottomhr">
{{ bottomText }}
</p>
</div>
</div>
</div>
</div>
</template>

<template #comment>
<div class="envelope-comment-wrap">
<SakuraComment />
</div>
</template>
</component>
</RouterView>
</template>
</SakuraPage>
</template>

<style lang="scss" scoped>
.envelope-maincontent {
width: 530px;
max-width: 100%;
margin-inline: auto;
margin-top: 20px;
position: relative;
z-index: 1;
box-sizing: border-box;
}

.form-wrap {
overflow: hidden;
width: 530px;
max-width: 100%;
height: var(--wrap-height, 447px);
position: relative;
top: 0;
transition: all 1s ease-in-out 0.3s;
z-index: 0;
cursor: pointer;
user-select: none;
box-sizing: border-box;
margin-inline: auto;
}

.form-wrap.opened {
height: var(--open-height, 1050px);
top: var(--open-offset, -200px);
}

.beforeimg {
position: absolute;
bottom: 126px;
left: 0;
right: 0;
width: 100%;
height: 317px;
z-index: 0;
pointer-events: none;
display: block;
object-fit: fill;
}

.afterimg {
position: absolute;
bottom: -2px;
left: 0;
right: 0;
width: 100%;
height: 259px;
z-index: 100;
pointer-events: none;
display: block;
object-fit: fill;
}

.envelope {
position: relative;
overflow: visible;
width: 500px;
max-width: calc(100% - 30px);
margin-inline: auto;
padding-top: 200px;
transition: all 1s ease-in-out 0.3s;
z-index: 10;
box-sizing: border-box;
}

.headerimg {
width: 100%;
display: block;
overflow: hidden;
pointer-events: none;
object-fit: cover;
}

.formmain {
background: #fff;
width: 95%;
max-width: 800px;
margin: 0 auto;
border-radius: 5px;
border: 1px solid rgba(0, 0, 0, 0.08);
overflow: hidden;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.18);
pointer-events: none;
}

.comments-main {
padding: 5px 20px 16px;
}

.title3 {
margin: 12px 0 8px;
text-decoration: none;
color: var(--sakura-color-primary, #fe9500);
text-align: center;
font-size: 1.15rem;
font-weight: 700;
}

.comments {
text-align: center;
border: 1px solid #ddd;
padding: 20px;
margin: 15px 0;
background-color: #eee;
line-height: 2;

p {
margin: 0;
font-size: 15px;
color: #333;
}
}

.bottomcontent {
text-align: center;
margin-top: 24px;
}

.bottomimg {
width: 100%;
margin: 5px auto;
display: block;
pointer-events: none;
}

.bottomhr {
margin: 8px 0 0;
font-size: 12px;
text-align: center;
color: #999;
}

.envelope-mobile {
display: none;
}

.envelope-comment-wrap {
position: relative;
z-index: 20;
width: 100%;
max-width: 800px;
margin-inline: auto;
margin-top: 24px;
margin-bottom: 40px;
padding-inline: 10px;
box-sizing: border-box;
}

@media screen and (max-width: 600px) {
.envelope-desktop {
display: none !important;
}

.envelope-mobile {
display: block;
}

.envelope-maincontent {
max-width: 100%;
margin-top: 12px;
}

.formmain {
width: 100%;
}

.comments-main {
padding: 5px 16px 12px;
}

.comments p {
font-size: 14px;
}
}

:global(html.dark) {
.formmain {
background: rgb(50, 50, 50);
border-color: rgba(255, 255, 255, 0.12);
box-shadow: 0 0 24px rgba(0, 0, 0, 0.45);
}

.title3 {
color: rgb(246, 214, 175);
}

.comments {
background: rgba(90, 90, 90, 0.8);
border-color: rgba(255, 255, 255, 0.85);
color: #fff;

p {
color: #fff;
}
}

.bottomhr {
color: #aaa;
}
}
</style>

<style lang="scss">
.sakura-comment-page {
width: 100%;
overflow-x: clip;

.sakura-one-columns,
.sakura-triple-columns {
width: 100%;
max-width: 100%;
justify-items: center;
}

.sakura-page-content {
width: 100%;
max-width: 900px;
margin-inline: auto;
overflow: visible;
display: flex;
flex-direction: column;
align-items: center;
box-sizing: border-box;
}

.sakura-page-content > * {
width: 100%;
max-width: 800px;
margin-inline: auto;
box-sizing: border-box;
}

main {
width: 100%;
overflow: visible;
}
}
</style>

提一句

留言页面要新建页面,index.md文件如下配置:

1
2
3
4
5
6
7
---
layout: comment
title: 不留下点什么吗
icon: i-ri-chat-1-line
nav: false
cover: https://你的图床.jpg
---

具体怎么创建页面看第一章教程末尾,顺便提一句,页面的访问方法,比如pages文件夹有一个comment文件夹,comment文件夹中有index.md文件,这就是一个页面了,在浏览器打开页面的方式就是:https://你的域名.com/comment

valaxy博客全局美化教程(六)
© AIOVTUE · https://20030327.xyz/posts/b75497b1/· 更新于 2026-06-02