文本/链接

typed - 文字打印效果js插件

阿里云


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

使用方法:

在页面中引入 jquery 和 typed.js 文件。

也想出现在这里?联系我们
创客主机
  1. <script src='path/to/jquery.min.js'></script>
  2. <script src='path/to/typed.js'></script>

HTML 结构:

使用一个元素来作为打印控制台容器。

  1. <span class="element"></span>

初始化插件:

可以通过纯 js 的方法来初始化 type.js 插件。

  1. document.addEventListener("DOMContentLoaded", function(){
  2.   Typed.new(".element", {
  3.     strings: ["First sentence.", "Second sentence."],
  4.     typeSpeed: 0
  5.   });
  6. });

也可以将 typed.js 作为 jquery 插件来使用。

  1. $(function(){
  2.   $(".element").typed({
  3.     strings: ["First sentence.", "Second sentence."],
  4.     typeSpeed: 0
  5.   });
  6. });

CSS 样式:

你需要使用下面的 css 样式来添加光标的闪烁效果。

  1. .typed-cursor{
  2.   opacity: 1;
  3.   -webkit-animation: blink 0.7s infinite;
  4.   -moz-animation: blink 0.7s infinite;
  5.   animation: blink 0.7s infinite;
  6. }
  7. @keyframes blink{
  8.   0% { opacity:1; }
  9.   50% { opacity:0; }
  10.   100% { opacity:1; }
  11. }
  12. @-webkit-keyframes blink{
  13.   0% { opacity:1; }
  14.   50% { opacity:0; }
  15.   100% { opacity:1; }
  16. }
  17. @-moz-keyframes blink{
  18.   0% { opacity:1; }
  19.   50% { opacity:0; }
  20.   100% { opacity:1; }
  21. }
  22. .typed-fade-out{
  23.     opacity: 0;
  24.     animation: 0;
  25.     transition: opacity .25s;
  26. }

配置参数:

typed.js 插件的所有可用配置参数如下:

  1. Typed.new(".element", {
  2.   strings: ["First sentence.", "Second sentence."],
  3.   // Optionally use an HTML element to grab strings from (must wrap each string in a <p>)
  4.   stringsElement: null,
  5.   // typing speed
  6.   typeSpeed: 0,
  7.   // time before typing starts
  8.   startDelay: 0,
  9.   // backspacing speed
  10.   backSpeed: 0,
  11.   // shuffle the strings
  12.   shuffle: false,
  13.   // time before backspacing
  14.   backDelay: 500,
  15.   // Fade out instead of backspace (must use CSS class)
  16.   fadeOut: false,
  17.   fadeOutClass: 'typed-fade-out',
  18.   fadeOutSpeed: 500, // milliseconds
  19.   // loop
  20.   loop: false,
  21.   // null = infinite
  22.   loopCount: null,
  23.   // show cursor
  24.   showCursor: true,
  25.   // character for cursor
  26.   cursorChar: "|",
  27.   // attribute to type (null == text)
  28.   attr: null,
  29.   // either html or text
  30.   contentType: 'html',
  31.   // call when done callback function
  32.   callback: function() {},
  33.   // starting callback function before each string
  34.   preStringTyped: function() {},
  35.   //callback for every typed string
  36.   onStringTyped: function() {},
  37.   // callback for reset
  38.   resetCallback: function() {}
  39. });

typed.js 控制台打印文字效果 js 插件的 egithub 地址为:https://github.com/mattboldt/typed.js

typed - 文字打印效果 js 插件

已有 652 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!