文本/链接

JS绘制文字动画特效插件

阿里云


这是 js 绘制文字动画特效插件。该插件通过在 js 中配置要绘制的文字、大小、颜色等属性,就可以在屏幕中指定文字实现文字的绘画过程。

使用方法

在页面中引入 vara.min.js 文件。

也想出现在这里?联系我们
创客主机
  1. <script src="./src/vara.min.js" type="text/javascript"></script>

HTML 结构

使用一个<div>元素作为文字绘画的容器。

  1. <div id="container"></div>

初始化插件

然后通过下面的方法来初始化插件。

  1. new Vara("#element","font.json",[{
  2.   text:"Handwritten"
  3. }],{
  4.   fontSize:46
  5. });

配置参数

该 js 绘制文字动画特效插件的可用配置参数有:

  1. new Vara("#container","font.json",[
  2. {
  3.   text:"Hello World", // String, text to be shown
  4.   fontSize:24, // Number, size of the text
  5.   strokeWidth:.5, // Width / Thickness of the stroke
  6.   color:"black", // Color of the text
  7.   id:"", // String or integer, for if animations are called manually or when using the get() method. Default is the index of the object.
  8.   duration:2000, // Number, Duration of the animation in milliseconds
  9.   textAlign:"left", // String, text align, accepted values are left,center,right
  10.   x:0, // Number, x coordinate of the text
  11.   y:0, // Number, y coordinate of the text
  12.   fromCurrentPosition:{ // Whether the x or y coordinate should be from its calculated position, ie the position if x or y coordinates were not applied
  13.     x:true, // Boolean
  14.     y:true, // Boolean
  15.   },
  16.   autoAnimation:true, // Boolean, Whether to animate the text automatically
  17.   queued:true, // Boolean, Whether the animation should be in a queue
  18.   delay:0,     // Delay before the animation starts in milliseconds
  19.   letterSpacing:0 // Number, space between each character
  20. }],{
  21.   // The options given below will be applicable to every text created,
  22.   // however they will not override the options set above.
  23.   // They will work as secondary options.
  24.   fontSize:24, // Number, size of the text
  25.   strokeWidth:.5, // Width / Thickness of the stroke
  26.   color:"black", // Color of the text
  27.   duration:2000, // Number, Duration of the animation in milliseconds
  28.   textAlign:"left", // String, text align, accepted values are left,center,right
  29.   autoAnimation:true, // Boolean, Whether to animate the text automatically
  30.   queued:true, // Boolean, Whether the animation should be in a queue
  31.   letterSpacing:0
  32. })

方法

该 js 绘制文字动画特效插件的可用方法有:

.ready(function):当字体被加载完成,元素准备就绪时执行该方法。其它方法在该方法内执行

.get(id):返回字符和容器对象。字符是一个 svg g 元素的数组

.draw(id):用于当 autoAnimation:false 时手动绘制文字动画

.animationEnd(function(i,o){}):用于在动画结束时触发一个函数

.playAll():开始所有的文字动画
Github 网址:https://github.com/akzhy/Vara

JS 绘制文字动画特效插件

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

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

发表回复

热销模板

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

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