Skip to content

Commit 1793583

Browse files
committed
feat: first screen description add typewriter effect
1 parent e3a1a6e commit 1793583

File tree

5 files changed

+106
-34
lines changed

5 files changed

+106
-34
lines changed

layout/_partial/first-screen.ejs

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<%
22
const { description: fs_description, hitokoto: fs_hitokoto } = theme?.style?.first_screen || {}
3-
const { description: c_description } = config
4-
let final_description = fs_description || c_description || ''
3+
let final_description = fs_description || ''
54
final_description = final_description.split('||').map(desc => desc.trim())
65
if (final_description.length > 2) { final_description.length = 2 }
76
const { enable: sc_enable, links: sc_links } = theme?.social_contact || {}
@@ -12,9 +11,15 @@ const { enable: sc_enable, links: sc_links } = theme?.social_contact || {}
1211
1312
<div class="middle-placeholder border-box">
1413
<% if (final_description.length || fs_hitokoto === true) { %>
15-
<div class="description hitokoto">
16-
<% for (const idx in final_description) { %>
17-
<div class="desc-item"><%= final_description[idx] %></div>
14+
<div class="description border-box">
15+
<% if (fs_hitokoto === true) { %>
16+
<div class="desc-item border-box"><span class="desc hitokoto"></span><span class="cursor"></span></div>
17+
<% } else { %>
18+
<% for (const idx in final_description) { %>
19+
<% if (final_description[idx]) { %>
20+
<div class="desc-item border-box"><span class="desc"><%= final_description[idx] %></span><span class="cursor"></span></div>
21+
<% } %>
22+
<% } %>
1823
<% } %>
1924
</div>
2025
<% } %>
@@ -65,6 +70,5 @@ const { enable: sc_enable, links: sc_links } = theme?.social_contact || {}
6570
</div>
6671
<% } %>
6772
</div>
68-
6973
</div>
7074
</div>

scripts/helpers/export-config.js

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ hexo.extend.helper.register('exportThemeConfig', function () {
4040
style: theme.style || {},
4141
local_search: theme.local_search || {},
4242
code_block: theme.code_block || {},
43-
side_tools: theme.side_tools || {},
4443
pjax: theme.pjax || {},
4544
lazyload: theme.lazyload || {},
4645
comment: theme.comment || {},

source/css/common/animated.styl

+34-25
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,34 @@ transition-t(property, delay, duration, function) {
4242
}
4343

4444

45+
.title-hover-animation {
46+
position relative
47+
display inline-block
48+
color var(--text-color-2)
49+
line-height 1.3
50+
vertical-align top
51+
border-bottom none
52+
53+
&::before {
54+
position absolute
55+
bottom -4px
56+
left 0
57+
width 100%
58+
height 2px
59+
background-color var(--text-color-2)
60+
transform scaleX(0)
61+
visibility hidden
62+
content ""
63+
transition-t("visibility transform", "0, 0", "0.2, 0.2", "ease-in-out, ease-in-out")
64+
}
65+
66+
&:hover::before {
67+
transform scaleX(1)
68+
visibility visible
69+
}
70+
}
71+
72+
4573
@keyframes fade-in-down {
4674
0% {
4775
transform translateY(-50px)
@@ -84,31 +112,12 @@ transition-t(property, delay, duration, function) {
84112
}
85113
}
86114

87-
.title-hover-animation {
88-
position relative
89-
display inline-block
90-
color var(--text-color-2)
91-
line-height 1.3
92-
vertical-align top
93-
border-bottom none
94-
95-
&::before {
96-
position absolute
97-
bottom -4px
98-
left 0
99-
width 100%
100-
height 2px
101-
background-color var(--text-color-2)
102-
transform scaleX(0)
103-
visibility hidden
104-
content ""
105-
transition-t("visibility transform", "0, 0", "0.2, 0.2", "ease-in-out, ease-in-out")
115+
@keyframes blink-caret {
116+
from
117+
to {
118+
opacity 0
106119
}
107-
108-
&:hover::before {
109-
transform scaleX(1)
110-
visibility visible
120+
50% {
121+
opacity 1
111122
}
112123
}
113-
114-

source/css/layout/_partial/first-screen.styl

+12-2
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,23 @@ $first-screen-img = $temp-img ? $temp-img : '/images/bg.svg'
5454
color var(--first-screen-font-color-dark)
5555

5656
.desc-item {
57-
color var(--first-screen-font-color-dark)
57+
.desc
58+
.cursor {
59+
color var(--first-screen-font-color-dark)
60+
}
5861
}
5962
}
6063

6164

6265
.desc-item {
63-
color var(--first-screen-font-color-light)
66+
.desc {
67+
color var(--first-screen-font-color-light)
68+
}
69+
70+
.cursor {
71+
color var(--first-screen-font-color-light)
72+
animation blink-caret 0.8s step-end infinite
73+
}
6474
}
6575

6676

source/js/utils.js

+50
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,53 @@ KEEP.initUtils = () => {
561561
})
562562
})
563563
})
564+
},
565+
566+
initTypewriter() {
567+
const fsc = KEEP.theme_config?.style?.first_screen || {}
568+
const isHitokoto = fsc?.hitokoto === true
569+
570+
if (fsc?.enable !== true) {
571+
return
572+
}
573+
574+
if (fsc?.enable === true && !isHitokoto && !fsc?.description) {
575+
return
576+
}
577+
578+
const descBox = document.querySelector('.first-screen-content .description')
579+
if (descBox) {
580+
descBox.style.opacity = '0'
581+
582+
setTimeout(
583+
() => {
584+
descBox.style.opacity = '1'
585+
const descItemList = descBox.querySelectorAll('.desc-item')
586+
descItemList.forEach((descItem) => {
587+
const desc = descItem.querySelector('.desc')
588+
const cursor = descItem.querySelector('.cursor')
589+
const text = desc.innerHTML
590+
desc.innerHTML = ''
591+
let charIndex = 0
592+
593+
if (text) {
594+
const typewriter = () => {
595+
if (charIndex < text.length) {
596+
desc.textContent += text.charAt(charIndex)
597+
charIndex++
598+
setTimeout(typewriter, 100)
599+
} else {
600+
cursor.style.display = 'none'
601+
}
602+
}
603+
604+
typewriter()
605+
}
606+
})
607+
},
608+
isHitokoto ? 400 : 300
609+
)
610+
}
564611
}
565612
}
566613

@@ -596,4 +643,7 @@ KEEP.initUtils = () => {
596643

597644
// tabs active handle
598645
KEEP.utils.tabsActiveHandle()
646+
647+
// first screen typewriter
648+
KEEP.utils.initTypewriter()
599649
}

0 commit comments

Comments
 (0)