Hexo Volantis主题副标题以打字效果输出 Hitokoto

my blog
Posts: Hexo Volantis主题副标题以打字效果输出 Hitokoto

前言

Hexo Volantis主题副标题以打字效果输出 Hitokoto

步骤

修改 _config.yml

import body_end加入 js 代码

<script>const textElement = document.querySelector('.top .subtitle'); let charIndex = 0; let isDeleting = false; let hitokotoText = ''; let typingInterval; const typingSpeed = 180; const deletingSpeed = 100; const delayBetweenCycles = 2500; function typeWriter() { if (isDeleting) { textElement.innerHTML = hitokotoText.slice(0, charIndex--); } else { textElement.innerHTML = hitokotoText.slice(0, ++charIndex); } if (!isDeleting && charIndex === hitokotoText.length) { setTimeout(() => isDeleting = true, delayBetweenCycles); } else if (isDeleting && charIndex === 0) { isDeleting = false; clearInterval(typingInterval); fetchHitokoto(); return; } const speed = isDeleting ? deletingSpeed : typingSpeed; typingInterval = setTimeout(typeWriter, speed); } function fetchHitokoto() { fetch('https://v1.hitokoto.cn').then(response => response.json()).then(data => { hitokotoText = data.hitokoto; charIndex = 0; typeWriter(); }).catch(console.error); } fetchHitokoto();</script>

_config.yml 示例:

import:
  body_end:
    - "<script>const textElement = document.querySelector('.top .subtitle'); let charIndex = 0; let isDeleting = false; let hitokotoText = ''; let typingInterval; const typingSpeed = 180; const deletingSpeed = 100; const delayBetweenCycles = 2500; function typeWriter() { if (isDeleting) { textElement.innerHTML = hitokotoText.slice(0, charIndex--); } else { textElement.innerHTML = hitokotoText.slice(0, ++charIndex); } if (!isDeleting && charIndex === hitokotoText.length) { setTimeout(() => isDeleting = true, delayBetweenCycles); } else if (isDeleting && charIndex === 0) { isDeleting = false; clearInterval(typingInterval); fetchHitokoto(); return; } const speed = isDeleting ? deletingSpeed : typingSpeed; typingInterval = setTimeout(typeWriter, speed); } function fetchHitokoto() { fetch('https://v1.hitokoto.cn').then(response => response.json()).then(data => { hitokotoText = data.hitokoto; charIndex = 0; typeWriter(); }).catch(console.error); } fetchHitokoto();</script>"

建立或修改 source\_volantis\style.styl

加入以下代码

// 副标题打字效果
.top .subtitle
  position: relative
  display: inline-block

.top .subtitle::after
  content: '|'
  position: absolute
  right: -10px
  animation: blink 0.8s step-end infinite

@keyframes blink
  0%, 50%
    opacity: 1
  51%, 100%
    opacity: 0

修改 _config.volantis.yml

cover:
  subtitle: ":D 获取中..."
  • 8
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值