D3.js 动画 过渡效果 (V3版本)
var width = 600;
var height = 400; var svg = d3.select("#body")
.append("svg")
.attr("width",width)
.attr("height",height) svg.append("rect")
.attr("fill","yellow")
.attr("x",100)
.attr("y",100)
.attr("width",100)
.attr("height",30)
.transition()
.attr("width",300)


var rect = svg.append("rect")
.attr("fill","yellow")
.attr("x",100)
.attr("y",100)
.attr("width",100)
.attr("height",30)
//打印rect
console.log(rect) //rect是选择集
//启动过渡效果
var rectTran = rect.transition()
//打印rectTran
console.log(rectTran) //rectTran是一个过渡对象


var rect = svg.append("rect")
.attr("fill","yellow")
.attr("x",100)
.attr("y",100)
.attr("width",100)
.attr("height",30)
var rectTran = rect.transition()
.delay(500) //延迟500ms再开始
.duration(1000) //过渡时长为1000ms
.ease("blunce") //过渡样式
.attr("width",300) //目标属性
var rect = svg.append("rect")
.attr("fill","yellow")
.attr("x",100)
.attr("y",100)
.attr("width",100)
.attr("height",30)
var rectTran = rect.transition() //开始一个过渡
.attr("width",300) //目标宽度为300
.transition() //开始一个过渡
.attr("height",300) //目标高度为300
.transition() //开始一个过渡
.attr("width",100) //目标宽度为100
.transition() //开始一个过渡
.attr("height",100) //目标高度为100
.attr("width",100)
.transition()
.attr("width",300)
var rect = svg.append("rect")
.attr("fill","yellow")
.attr("x",100)
.attr("y",100)
.attr("width",100)
.attr("height",30)
var rectTran = rect.transition()
.duration(2000)
.attrTween("width",function(d,i,a){
return function(t){
return Number(a) + t * 300
}
})
svg.append("rect")
.attr("fill","yellow")
.attr("x",100)
.attr("y",100)
.attr("width",100)
.attr("height",30)
.transition()
.duration(2000)
.attr("fill",'red')
svg.append("rect")
.attr("fill","yellow")
.attr("x",100)
.attr("y",100)
.attr("width",100)
.attr("height",30)
.transition()
.duration(2000)
.attr("width",300)
var text = svg.append("text")
.attr("fill","white")
.attr("x",150)
.attr("y",100)
.attr("dy","1.2em")
.attr("text-anchor","end")
.text(100)
var initx = text.attr("x")
var initText = text.text()
var textTran = text.transition()
.duration(2000)
.tween("text",function(){
return function(t){
d3.select(this)
.attr("x",Number(initx) + t * 250 )
.text(Math.floor(Number(initText) + t * 300 ))
}
})
//当t为0时,函数体力的操作是:
d3.select(this)
.attr("x",150 + 0 * 250)
.text(Math.floor(100 + 0 * 300)) //当t为1时,函数体里的操作是:
d3.select(this)
.attr("x",150 + 1 * 250 )
.text(Math.floor(100 + 1 * 300))

var rect = svg.append("rect")
.attr("fill","yellow")
.attr("x",100)
.attr("y",100)
.attr("width",100)
.attr("height",30)
rect.transition()
.attr("width",0)
.remove()
D3.js 动画 过渡效果 (V3版本)的更多相关文章
- D3.js 线段生成器 (V3版本)
线段生成器 与线段生成器相关的方法: d3.svg.line() //创建一个线段生成器. line(data) //使用线段生成器绘制data数据. line.x([x]) //设置或获取线 ...
- D3.js 弦生成器(V3版本)
弦生成器(Chord Generator) 弦生成器(Chord Generator)根据两段弧来绘制弦,共有五个访问器,分别为source().target().radius().startAn ...
- D3.js 区域生成器 (V3版本)
区域生成器(Area Generator) 区域生成器(Area Generator)用于生成一块区域,使用方法与线段生成器类似.线段生成器地址:数据访问器有x().x0().x1().y().y ...
- D3.js(v3)+react 制作 一个带坐标与比例尺的柱形图 (V3版本)
现在用D3.js + react做一个带坐标轴和比例尺的柱形图.我已经尽力把代码全部注释上了,最后我也会把完整柱形图代码奉上.如果还有疑惑的,可以去翻看一下我之前介绍的方法,以下方法都有介绍到. 还有 ...
- D3.js的v5版本入门教程(第十二章)—— D3.js中各种精美的图形
D3.js的v5版本入门教程(第十二章) D3中提供了各种制作常见图形的函数,在d3的v3版本中叫布局,通过d3.layout.xxx,来新建,但是到了v5,新建一个d3中基本的图形的方式变了(我也并 ...
- D3.js的v5版本入门教程(第十章)
在这一章我们干点有趣的事——让我们上一章绘制的图表动起来,这样岂不是很有意思 为了让图表动起来,我们还是需要以下新的知识点 .attr(xxx) .transition() .attr(xxx),tr ...
- D3.js使用过程中的常见问题(D3版本D3V4)
目录 一.学习D3我必须要学习好SVG矢量图码? 二.如何理解D3给Dom节点绑定数据时的Update.Enter和Exit模式 三.D3绑定数据时用datum与data有什么不一样? 四.SVG图中 ...
- d3.js制作连线动画图和编辑器
此文章为原创文章,原文地址:https://www.cnblogs.com/eagle1098/p/11431679.html 连线动画图 编辑器 效果如上图所示.本项目使用主要d3.jsv4制作,分 ...
- D3.js的v5版本入门教程(第十三章)—— 饼状图
D3.js的v5版本入门教程(第十三章) 这一章我们来绘制一个简单的饼状图,我们只绘制构成饼状图基本的元素——扇形.文字,从这一章开始,内容可能有点难理解,因为每一章都会引入比较多的难理解知识点,在这 ...
随机推荐
- hduoj-1301 Jungle Roads(最小生成树-克鲁斯卡尔和普里姆求解)
普里姆求解: #include<cstdio> #include<cmath> #include<cstring> #include<iostream> ...
- Javascript连续赋值
Javascript对象属于引用类型,将对象赋值给变量相当于将对象地址赋值给变量 let a = {n: 1}; let b = a; a.x = a = {n: 2}; //运算符的优先级 cons ...
- USACO 2014 US Open Fair Photography /// 技巧
题目大意: 给定n头奶牛 给定n头奶头所在位置和品种 品种只有G H两种 求一段区间的长度 要求区间内包含的品种满足各品种的数量相同 将一个品种的值设为1 另一个设为-1 假设 i<j 而 1~ ...
- add characteristic to color
Problem: add a new Char. name D_COI6 that the description is Injected coloration #7 (COI6) in the D_ ...
- 配置ssh免密登录问题
有小伙伴的系统需要做免密登录.配置比较简单,ssh-keygen然后生成authorized_keys 文件即可. 但是配置好之后,修改相应用户的家目录权限后,则免密登录就失效了. 经过试验,发现家目 ...
- JSP界面引用百度地图获取坐标
需求: 需要在JSP界面上引用百度地图,文本框中输入地址之后,自动拿到在百度地图上的经纬度 解决步骤: 1.引入百度地图api: head中进行引用<script type="text ...
- 换了SSD发现plank也好了
我的Dock用的是plank,很简单很好用.为什么不用Docky还有其他什么玩意儿呢?plank很简单很好用,资源占用很少,可以智能隐藏,you nearly can't feel it but yo ...
- MySQL源码编译与初始化
MySQL源码编译与初始化 链接:https://pan.baidu.com/s/1ANGg3Kd_28BzQrA5ya17fQ 提取码:ekpy 复制这段内容后打开百度网盘手机App,操作更方便哦 ...
- SharpZipLib 文件/文件夹 过滤
这里就不说压缩/解压了.网上教程太多. 主要说一下,解压时,如何过滤某些文件/文件夹 参考地址:https://github.com/icsharpcode/SharpZipLib/wiki/Fast ...
- groupby 技术
分组键可以有很多形式,且类型不必相同: 1.列表或数组,其长度与待分组的轴一样 2.表示DataFrame某个列名的值 3.字典或Series,给出待分组轴上的值与分组名之间的对应关系 4.函数,用于 ...