超酷创意分段式SVG文字动画特效

简要教程

这是一款基于segment.js制作的非常有创意的分段式SVG文字动画特效。这个文字动画特效通过动画SVG的描边路径来制作各种文字的动画效果,效果非常的赞。

这个SVG文字动画特效的第一个DEMO中的最后几个例子使用了mo.js插件,一款由Oleg Solomka编写的用于制作网页图形动画的JavaScript库插件。通过mo.js,可以制作出效果更为震撼的文字动画效果。

超酷创意分段式SVG文字动画特效

特效中使用的字体是exquisite lowercase font,一套极富创意的WEB字体。

使用方法

要使用该SVG文字动画特效,要在页面中引入segment.js,它用于动画SVG路径,d3-ease,用于制作easing动画过渡效果,以及letters.js。

  1.                   

登录后复制

HTML结构

可以使用一个

容器来包裹需要制作动画效果的文字。

  1. my text

登录后复制

初始化插件

然后我们就可以在JavaScript中获取这个元素,通过配置参数来制作绘制文字的动画。所有的参数选项(除了individualDelays)都可以设置为以下的值:

单个值:可以被所有字母接收。

数组:数组中的第一个元素会被第一个字母接收,第二个元素被第二个字母接收,以此类推。

下面是一个使用配置参数的例子:

  1. // Selecting the container elementvar el = document.querySelector('.my-text'); // All the possible options (these are the default values)// Remember that every option (except individualDelays) can be defined as single value or arrayvar options = {    size: 100,         // Font size, defined by the height of the letters (pixels)    weight: 1,         // Font weight (pixels)    rounded: false,    // Rounded letter endings    color: '#5F6062',  // Font color    duration: 1,       // Duration of the animation of each letter (seconds)    delay: [0, 0.05],  // Delay animation among letters (seconds)    fade: 0.5,         // Fade effect duration (seconds)    easing: d3_ease.easeCubicInOut.ease,   // Easing function    individualDelays: false,                   // If false (default), every letter delay increase gradually, showing letters from left to right always.      If you want to show letters in a disorderly way, set it to true, and define different delays for the desired letters.}; // Initializing the text (Letters parameters: container-element, options)var myText = new Letters(el, options);

登录后复制

通过上面的配置,我们已经定义了文字显示和动画的选项,插件会在容器中生成SVG文字。默认情况下,文字是被隐藏的,如何触发文字动画,可以参看下面的方法。

  1. // Show letters with the default options definedmyText.show(); // Hide letters with the default options definedmyText.hide(); // Toggle letters with the default options definedmyText.toggle(); // An example with all the possible options for triggers// Parameters (JSON): duration, delay, fade, easing, individualDelays, callbackvar newOptions = {    duration: 2,    delay: 0.2,    fade: 1,    easing: d3_ease.easeCircleInOut.ease,    individualDelays: false,    callback: function(){        myText.hide();    }};// These new options will override the options defined in the initializationmyText.show(newOptions); // Show letters instantly, without any animation at all// There is a hideInstantly and toggleInstantly function, toomyText.showInstantly();  // Shortcut for myText.show(0, 0, 0);

登录后复制

每一个SVG字母都被分配一个letter class类,例如:letter-(a, b, c, …),以及letter-(1, 2, 3, …)。通过这些class我们可以自定义字母的样式,例如设置margin值或定位方式等。

  1. /* Setting margin among all letters */.letter {  margin: 0 10px;} /* Setting background to letter m */.letter-{  background-color: lightsalmon;}

登录后复制

以上就是超酷创意分段式SVG文字动画特效的内容,更多相关内容请关注PHP中文网(www.php.cn)!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

点点赞赏,手留余香

给TA打赏
共0人
还没有人赞赏,快来当第一个赞赏的人吧!
    编程技术

    HTML5学习笔记简明版(2):新元素之section,article,aside

    2025-4-1 8:29:48

    编程技术

    基于HTML5 Canvas和Rebound动画的Loading加载动画特效

    2025-4-1 8:31:36

    0 条回复 A文章作者 M管理员
    欢迎您,新朋友,感谢参与互动!
      暂无讨论,说说你的看法吧
    个人中心
    购物车
    优惠劵
    今日签到
    私信列表
    搜索