SVG.js动画——timeline方法与内置控制器

news/2024/10/23 5:43:48/

Easing

可以使用runner的ease()方法更改动画的缓和程度。
所有可用的ease类型包括:

  • <>: ease in and out
  • : ease out

  • <: ease in
  • -: linear
  • a function
  • beziere(x1, y1, x2, y2) // 贝塞尔曲线
  • step(steps, stepPosition)

beziere()和step()方法为您创建了一个easing函数,然后可以将其传递给ease()

var runner = new SVG.Runner({duration: 1000})// use a string
runner.ease('<>')// or pass a function
runner.ease(SVG.easing.beziere(x1, y1, x2, y2))
runner.ease(SVG.easing.step(5, 'jump-end'))

要了解更简单的公式,请查看svg.easing.js插件。

SVG.Timeline

SVG.Timeline把runner元素当做动画元素。runner可以在同一temline上安排,以编排更大的动画。

1)finish()

此方法完成整个时间线。所有值都被设置为其相应的结束值,并且每个动画都被完成:

rect.animate().move(200, 200).animate().dmove(50,50).size(300,400)
rect.timeline().finish() // rect at 250,250 with size 300,400

2)pause()

暂停时间线:

rect.animate().move(200, 200)
rect.mouseover(function() { this.timeline().pause() })

3)play()

取消时间线的连接:

rect.animate().move(200, 200)rect.mouseover(function() { this.timeline().pause() })
rect.mouseout(function() { this.timeline().play() })

4)reverse()

在翻转的时间线上播放动画:

// will run from 100,100 to rects initial position
// 没有参数时表示初始位置
rect.animate(3000).move(100, 100)
rect.timeline().reverse()// sets direction to backwards
// 动画倒退
rect.timeline().reverse(true)// sets direction to forwards
// 动画前进
rect.timeline().reverse(false)

5)stop()

停止时间线并将时间设置回零:

rect.animate().move(200, 200)
rect.timeline().stop()

6)speed()

更改时间线的速度。负速度将反转时间轴:

rect.animate().move(200, 200)
rect.timeline().speed(2)

7)time()

设置时间线的当前时间:

rect.animate().move(200, 200)
rect.timeline().time(100)

8)seek()

按增量查找时间:

rect.animate().move(200, 200)
rect.timeline().seek(100)

9)persist()

设置runner在执行后的默认处理方式。通常删除运行程序以清除内存:

rect.animate().move(200, 200)rect.timeline().persist(100) // persist runner for 100ms more than their end time
rect.timeline().persist(true) // never delete runners

10)source()

更改时间线的时间源:

rect.animate().move(200, 200)
rect.timeline().source(fn)

11)schedule()

在时间线上安排runner:

var timeline = new SVG.Timeline()
var runner = new SVG.Runner()
runner.move(100, 100)
timeline.schedule(runner, 100, 'now') // runner, delay, when - see animate()

12)unschedule()

取消计划/从时间表中删除runner:

var timeline = new SVG.Timeline()
var runner = new SVG.Runner()
runner.move(100, 100)
timeline.schedule(runner, 100, 'now')
timeline.unschedule(runner) // same as runner.unschedule()

Controllers

可以使用控制器来控制动画,而不是使用ease()方法。SVG.js带有两个内置控制器。SVG.Spring和SVG.PID。

element.animate(new SVG.Spring(settleTime)).move(200, 200)
element.animate(new SVG.PID(p, i, d)).move(200, 200)

正如您可能注意到的,指定的是控制器而不是持续时间,因为只有控制器本身知道动画何时完成。

这就是为什么不可能用控制器编排或反转动画的原因。

Orchestrate Animations

要创建包含多个元素的更大的动画,这些元素都绑定到同一时间线,您可以同时使用SVG.timeline和SVG.Runner:

var timeline = new SVG.Timeline()var rect1 = draw.rect(100, 200)
var rect2 = draw.rect(200, 100)rect1.timeline(timeline)
rect2.timeline(timeline)rect1.animate(300, 0, 'absolute').move(300, 300) // start at time 0 of timeline
rect2.animate(400, 200, 'absolute').move(500, 500) // start at time 200 of timeline

视频讲解

视频讲解


http://www.ppmy.cn/news/75301.html

相关文章

组件123456789

前言&#xff1a;相信看到这篇文章的小伙伴都或多或少有一些编程基础&#xff0c;懂得一些linux的基本命令了吧&#xff0c;本篇文章将带领大家服务器如何部署一个使用django框架开发的一个网站进行云服务器端的部署。 文章使用到的的工具 Python&#xff1a;一种编程语言&…

05 Android开机启动之SystemServer

Android开机启动之SystemServer(SS) 一、梳理SystemServer启动流程 从上面整个Android开机启动思维导图(android 5.0的启动组成图)中可以看到: SystemServer是从Zygote中启动的。 开机->bootloader->kernel->init->zygote->SystemServer 二、SystemServe…

Java阶段三Day04

Java阶段三Day04 文章目录 Java阶段三Day04Vue框架Vue框架概述如何引入vue.jsVue框架的HelloWorldVue框架执行原理 基本指令文本相关指令属性绑定和双向绑定事件绑定v-for循环遍历指令显示隐藏相关指令 Vue框架 Vue框架概述 Vue是一种流行的渐进式JavaScript框架&#xff0c;…

彻底理解粘性定位 - position: sticky(IT枫斗者)

彻底理解粘性定位 - position: sticky 介绍 粘性定位可以被认为是相对定位(position: relative)和固定定位(position: fixed)的混合。元素在跨越特定阈值前为相对定位&#xff0c;之后为固定定位。例如: .sticky-header { position: sticky; top: 10px; }在 视口滚动到元素…

springboot使用Mybatis-plus分页插件

1. 引入依赖 在 pom.xml 文件中添加 MyBatis Plus 和分页插件的依赖&#xff1a; <dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>{mybatis-plus-version}</version> &…

拿两个字母就能注册商标了吗?

我们来关注一些常见的又让人有点捂脸的现象。比如说&#xff0c;用几个字母或者一个单词注册商标。 黄小明我在办案中就遇到了一个这样的问题。该公司的注册商标被人使用在了一模一样的商品上&#xff0c;然后损失很大&#xff0c;然后该公司就报了警&#xff0c;警察就去把卖假…

Unity UI -- (5)增加基础按钮功能

分析分析一些常见UI 良好的UI设计会清晰地和用户沟通。用户知道他们能和屏幕上哪些东西交互&#xff0c;哪些不能。如果他们进行了交互&#xff0c;他们也要清楚地知道交互是否成功。换句话说&#xff0c;UI要提供给用户很多反馈。 我们可以来看看在Unity里或者在计算机上的任何…

【5.20】五、安全测试——渗透测试

目录 5.3 渗透测试 5.3.1 什么是渗透测试 5.3.2 渗透测试的流程 5.3 渗透测试 5.3.1 什么是渗透测试 渗透测试是利用模拟黑客攻击的方式&#xff0c;评估计算机网络系统安全性能的一种方法。这个过程是站在攻击者角度对系统的任何弱点、技术缺陷或漏洞进行主动分析&#x…