
typed.js 是一款模拟控制台打印文字效果的 js 插件。typed.js 可以自由的控制要打印的文字,以及打印的速度等,可以制作出逼真的打印文字效果。
在页面中引入 jquery 和 typed.js 文件。

<script src='path/to/jquery.min.js'></script>
<script src='path/to/typed.js'></script>
使用一个元素来作为打印控制台容器。
<span class="element"></span>
可以通过纯 js 的方法来初始化 type.js 插件。
document.addEventListener("DOMContentLoaded", function(){
Typed.new(".element", {
strings: ["First sentence.", "Second sentence."],
typeSpeed: 0
});
});
也可以将 typed.js 作为 jquery 插件来使用。
$(function(){
$(".element").typed({
strings: ["First sentence.", "Second sentence."],
typeSpeed: 0
});
});
你需要使用下面的 css 样式来添加光标的闪烁效果。
.typed-cursor{
opacity: 1;
-webkit-animation: blink 0.7s infinite;
-moz-animation: blink 0.7s infinite;
animation: blink 0.7s infinite;
}@keyframes blink{
0% { opacity:1; }
50% { opacity:0; }
100% { opacity:1; }
}@-webkit-keyframes blink{
0% { opacity:1; }
50% { opacity:0; }
100% { opacity:1; }
}@-moz-keyframes blink{
0% { opacity:1; }
50% { opacity:0; }
100% { opacity:1; }
}.typed-fade-out{
opacity: 0;
animation: 0;
transition: opacity .25s;
}typed.js 插件的所有可用配置参数如下:
Typed.new(".element", {
strings: ["First sentence.", "Second sentence."],
// Optionally use an HTML element to grab strings from (must wrap each string in a <p>)stringsElement: null,
// typing speedtypeSpeed: 0,
// time before typing startsstartDelay: 0,
// backspacing speedbackSpeed: 0,
// shuffle the stringsshuffle: false,
// time before backspacingbackDelay: 500,
// Fade out instead of backspace (must use CSS class)fadeOut: false,
fadeOutClass: 'typed-fade-out',
fadeOutSpeed: 500, // milliseconds
// looploop: false,
// null = infiniteloopCount: null,
// show cursorshowCursor: true,
// character for cursorcursorChar: "|",
// attribute to type (null == text)attr: null,
// either html or textcontentType: 'html',
// call when done callback functioncallback: function() {},
// starting callback function before each stringpreStringTyped: function() {},
//callback for every typed stringonStringTyped: function() {},
// callback for resetresetCallback: function() {}
});
typed.js 控制台打印文字效果 js 插件的 egithub 地址为:https://github.com/mattboldt/typed.js
| 演示地址 | 下载地址 |
专业提供WordPress主题安装、深度汉化、加速优化等各类网站建设服务,详询在线客服!
