hexo中文字实现打字机效果

文字的打字机效果是否是感受蛮炫呢,实际上是用typed.js这个插件实现的哦~web


下载typed.js

  • With NPM

    npm install typed.jsnpm

  • With Yarn

    yarn add typed.jshexo

  • With Bower

    bower install typed.jssvg

详细内容戳 👉 typed.js官网oop


typed.js的使用

使用很是简单,在相对应的页面中加入如下代码就完成啦。插件

<script src="<%- theme.libs.js.typed %>"></script> //引入js文件
<script>
var options = {
    strings: [' <%- config.description %>', ' <%- config.descriptionEN %>'],
    typeSpeed: 120, //打印的速度。数值越大,速度越慢
    loop: true, //开启循环
    loopCount: Infinity, //设置循环次数,值为:Infinity,也能够使用数值
    backSpeed: 20, //延迟时间后才后退,值越大,延迟的时间就越长
    cursorChar: '^' //光标的符号,好比:
};
var typed = new Typed('#description', options);
</script>

代码中引入的src为<%- theme.libs.js.typed %>变量,是由于我用的主题hexo-theme-materyjs文件都是统一管理的,为了保持一致,我将npm i后的typed.min.js文件单独放在了theme的source/libs目录下,
并在theme_config.yml添加了libs的对应目录配置。code

若是光标改为表情会更赞哦~xml


写在最后

若是这篇文章对你有帮助或是喜欢的话,能够戳下方对小举赏一个哟😘ip