当前位置: 首页 > news >正文

Raphael入门实例:动画与箭头

raphael 实例

动画

隐藏和显示参数说明

?
1
2
3
4
5
6
7
8
9
10
11
12
13
var c = paper.circle(50, 50, 40);
 
function hide() {
   c.hide();
   setTimeout(show, 1000);
}
 
function show() {
   c.show();
   setTimeout(hide, 1000);
}
 
setTimeout(hide, 1000);
 

改变属性参数说明

?
1
2
3
4
5
6
7
8
9
10
var c = paper.circle(50, 50, 40);
 
function change_attr() {
   //改变颜色
   c.attr( 'stroke' , Raphael.hsb(Math.random(), 1, 1));
 
   setTimeout(change_attr, 1000);
}
 
setTimeout(change_attr, 1000);
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
var c = paper.circle(50, 50, 40);
 
function change_one_attr() {
   //改变一个属性
   c.attr( 'stroke' , '#FFF' );
 
   setTimeout(change_muti_attr, 1000);
}
 
function change_muti_attr() {
   //改变多个属性
   c.attr({
     cx: 50 + Math.random() * 120,               //圆心x坐标
     cy: 50 + Math.random() * 100,               //圆心y坐标
     r: 10 * (Math.random() * 5 + 1),            //半径
     stroke: Raphael.hsb(Math.random(), 1, 1)  //颜色
   });
 
   setTimeout(change_one_attr, 1000);
}
 
setTimeout(change_one_attr, 1000);
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 绘制箭头
var c = paper.path( "M10 10L100 10" ).attr({
   'arrow-end' : 'classic-wide-long' ,
   stroke: "#fff" ,
   "stroke-width" : 2
});
 
var c = paper.path( "M10 30L100 30" ).attr({
   'arrow-end' : 'block-wide-long' ,
   stroke: "#f00" ,
   "stroke-width" : 2
});
 
var c = paper.path( "M10 50L100 50" ).attr({
   'arrow-end' : 'open-wide-long' ,
   stroke: "#ff0" ,
   "stroke-width" : 2
});
 
var c = paper.path( "M10 70L100 70" ).attr({
   'arrow-end' : 'oval-wide-long' ,
   stroke: "#0f0" ,
   "stroke-width" : 2
});
 
var c = paper.path( "M10 90L100 90" ).attr({
   'arrow-end' : 'diamond-wide-long' ,
   stroke: "#0ff" ,
   "stroke-width" : 2
});
 

动画参数说明

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
var c = paper.circle(50, 50, 40);
 
function animate() {
   var ms = 1000;       // 播放动画,持续时间1000毫秒
 
   c.animate({
     cx: 50 + Math.random() * 120,               //圆心x坐标
     cy: 50 + Math.random() * 100,               //圆心y坐标
   }, ms);
 
   setTimeout(animate, 2000);
}
 
setTimeout(animate, 1000);
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// 效果同上,但是利用了动画结束时的回调函数
var c = paper.circle(50, 50, 40);
 
function animate() {
   var ms = 1000;
 
   c.animate({
     cx: 50 + Math.random() * 120,               //圆心x坐标
     cy: 50 + Math.random() * 100,               //圆心y坐标
   }, ms, function (){
     setTimeout(animate, 1000);
   });
}
 
setTimeout(animate, 1000);
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 效果同上,使用动画对象
var c = paper.circle(50, 50, 40);
 
function animate() {
   var ms = 1000;
   var anim = Raphael.animation({
     cx: 50 + Math.random() * 120,               //圆心x坐标
     cy: 50 + Math.random() * 100,               //圆心y坐标
   }, ms, function (){
     setTimeout(animate, 1000);
   });
 
   c.animate(anim);
}
 
setTimeout(animate, 1000);
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 效果同上,调用动画对象的delay()方法
var c = paper.circle(50, 50, 40);
 
function animate() {
   var ms = 1000;
   var anim = Raphael.animation({
     cx: 50 + Math.random() * 120,               //圆心x坐标
     cy: 50 + Math.random() * 100,               //圆心y坐标
   }, ms, function (){
     setTimeout(animate, 0);
   });
 
   c.animate(anim.delay(1000));
}
 
setTimeout(animate, 0);
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// 动画对象的过渡效果及repeat()方法
var c = paper.circle(50, 50, 40);
 
function animate() {
   var ms = 2000;
   var anim = Raphael.animation({
     50: {
       r: 60,
       stroke: '#f00'
     },
     100: {
       r: 40,
       stroke: '#fff'
     }
   }, ms);
 
   c.animate(anim.repeat( "Infinity" )); //Infinity为无限次
}
 
animate();
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 设置效果的曲线类型
var c = paper.circle(50, 50, 40);
 
function animate() {
   var ms = 1000;
   var easing = 'elastic' ;
 
   c.animate({
     cx: 50 + Math.random() * 120,               //圆心x坐标
     cy: 50 + Math.random() * 100,               //圆心y坐标
   }, ms, easing, function (){
     setTimeout(animate, 1000);
   });
}
 
setTimeout(animate, 1000);
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// 设置随机曲线类型
var c = paper.circle(50, 50, 40);
 
function animate() {
   var ms = 1000;
   var easing = [ 'elastic' , '' , 'bounce' , 'ease-in-out' ][Math.round(Math.random() * 3)];
 
   c.animate({
     cx: 50 + Math.random() * 120,               //圆心x坐标
     cy: 50 + Math.random() * 100,               //圆心y坐标
   }, ms, easing, function (){
     setTimeout(animate, 1000);
   });
}
 
setTimeout(animate, 1000);

相关文章:

  • Activity加载模式
  • Ubuntu下Alt+Tab快捷键不能用解决办法
  • Google Scholar 论文参考文献的自动生成
  • discuz X2.5自己写代码,获取当前登录的用户信息
  • 通过搭建一个精简的C语言开发环境了解一个C程序的执行过程
  • 【javascript基础】系列
  • 产品需求文档的写作(一) – 写前准备(信息结构图)
  • 【Nodejs开发】第1章 述与环境搭建
  • 在管理实际中,心态很重要,当你以欣赏的态度去看一件事,你便会看到许多优点,以批评的态度,你便会看到无数缺点。...
  • linux上未分区硬盘的格式化实践
  • 烂泥:【解决】windows live write报连接到日志时出错
  • 数据库持久连接理解
  • 怎么知道自己系统是32位,还是64位?
  • iOS ARC基本原理
  • (Mirage系列之二)VMware Horizon Mirage的经典用户用例及真实案例分析
  • [LeetCode] Wiggle Sort
  • “Material Design”设计规范在 ComponentOne For WinForm 的全新尝试!
  • 《Javascript高级程序设计 (第三版)》第五章 引用类型
  • 78. Subsets
  • SQL 难点解决:记录的引用
  • storm drpc实例
  • underscore源码剖析之整体架构
  • vuex 学习笔记 01
  • 大整数乘法-表格法
  • 基于游标的分页接口实现
  • 记一次和乔布斯合作最难忘的经历
  • 离散点最小(凸)包围边界查找
  • 用简单代码看卷积组块发展
  • 怎样选择前端框架
  • - 转 Ext2.0 form使用实例
  • 小白应该如何快速入门阿里云服务器,新手使用ECS的方法 ...
  • 智能情侣枕Pillow Talk,倾听彼此的心跳
  • ​ 轻量应用服务器:亚马逊云科技打造全球领先的云计算解决方案
  • ​​​​​​​​​​​​​​Γ函数
  • ​LeetCode解法汇总1410. HTML 实体解析器
  • ​软考-高级-信息系统项目管理师教程 第四版【第23章-组织通用管理-思维导图】​
  • ​一些不规范的GTID使用场景
  • #在 README.md 中生成项目目录结构
  • $GOPATH/go.mod exists but should not goland
  • (arch)linux 转换文件编码格式
  • (备忘)Java Map 遍历
  • (定时器/计数器)中断系统(详解与使用)
  • (二)斐波那契Fabonacci函数
  • (附源码)ssm智慧社区管理系统 毕业设计 101635
  • (附源码)计算机毕业设计SSM智能化管理的仓库管理
  • (九)信息融合方式简介
  • (没学懂,待填坑)【动态规划】数位动态规划
  • (十)T检验-第一部分
  • (转)菜鸟学数据库(三)——存储过程
  • (转载)hibernate缓存
  • . ./ bash dash source 这五种执行shell脚本方式 区别
  • .NET 中什么样的类是可使用 await 异步等待的?
  • .net6解除文件上传限制。Multipart body length limit 16384 exceeded
  • .NET分布式缓存Memcached从入门到实战
  • .NET国产化改造探索(三)、银河麒麟安装.NET 8环境