使用方法:将如下代码放置主题首页面自定义模块即可
<!--打字机一言开始-->
<script>
var yiyan = function (r) {
function t() {
return b[Math.floor(Math.random() * b.length)]
}
function e() {
return String.fromCharCode(94 * Math.random() + 33)
}
function n(r) {
for (var n = document.createDocumentFragment(), i = 0; r > i; i++) {
var l = document.createElement("span");
l.textContent = e(), l.style.color = t(), n.appendChild(l)
}
return n
}
function i() {
var t = o[c.skillI];
c.step ? c.step-- : (c.step = g, c.prefixP < l.length ? (c.prefixP >= 0 && (c.text += l[c.prefixP]), c.prefixP++) : "forward" === c.direction ? c.skillP < t.length ? (c.text += t[c.skillP], c.skillP++) : c.delay ? c.delay-- : (c.direction = "backward", c.delay = a) : c.skillP > 0 ? (c.text = c.text.slice(0, -1), c.skillP--) : (c.skillI = (c.skillI + 1) % o.length, c.direction = "forward")), r.textContent = c.text, r.appendChild(n(c.prefixP < l.length ? Math.min(s, s + c.prefixP) : Math.min(s, t.length - c.skillP))), setTimeout(i, d)
}
var l = "总有人间一两风,填我十万八千梦🍂", //固定一条
o = [""].map(function (r) { //多条顺序格式 "内容1","内容2"
return r + ""
}),
a = 25, //打字完等待重载时间
g = 1,
s = 1,
d = 80, //打字过程速度
b = [""],
c = {
text: "🍂", //固定开头内容,不打字效果
prefixP: -s,
skillI: 0,
skillP: 0,
direction: "forward",
delay: a,
step: g
};
i()
};
yiyan(document.getElementById('yiyan'));
</script>
<!--打字机一言结束-->