svg圆环缓冲动画
代码如下
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#hhn {
width: 500px;
height: 500px;
position: relative;
background: rgba(0,0,0,0.5);
}
</style>
</head>
<body>
<div id="hhn"></div>
</body>
<script src="../libs/d3.js"></script>
<script src="../libs/jquery.js"></script>
<script>
var chartCon = $('#hhn');
var domInfo = [{
id : 'circle1',
value : 32,
left : '5%',
top : '5%',
text : '通信'
},{
id : 'circle2',
value : 68,
left : '35%',
top : '5%',
color : 'rgba(199, 164, 14, 0.5)',
text : '物流'
},{
id : 'circle3',
value : 32,
left : '65%',
top : '5%',
text : '半导体'
},{
id : 'circle4',
value : 32,
left : '5%',
top : '53%',
text : '智能制造'
},{
id : 'circle5',
value : 68,
left : '35%',
top : '53%',
color : 'rgba(199, 164, 14, 0.5)',
text : '网络信息'
},{
id : 'circle6',
value : 32,
left : '65%',
top : '53%',
text : '其他'
}];
var dom;
$(domInfo).each(function(i,v){
chartCon.append('<div id='+v.id+' style="position:absolute;left:'+v.left+';top:'+v.top+';width:150px;height:150px;"></div>');
dom = document.getElementById(v.id);
$('<span>').css({
position: 'absolute',
width: '100%',
height: '20%',
textAlign:'center',
color: '#bbbcc0',
fontSize: 20,
top: '105%'
}).text(v.text).appendTo($(dom));
buildCircle(dom,v.value,v.color,v.id);
});
function buildCircle(el, value, vColor,vId) {
if (!d3.arc) d3.arc = d3.svg.arc;
if (!d3.pie) d3.pie = d3.layout.pie;
var svg = d3.select(el).append('svg')//给每个div添加svg元素
.attr('width', '100%')
.attr('height', '100%')
.attr('viewBox', '0 0 100 100');
var defs = svg.append('defs');
var id = 'color_' + Math.random();
var linear = defs.append('linearGradient')
.attr('x1', 0)
.attr('y1', 0)
.attr('x2', 0)
.attr('y2', 1)
.attr('id', id);
linear.append('stop')
.attr('stop-color', vColor || 'rgba(2,135,188,0.5)')
.attr('offset', 0);
linear.append('stop')
.attr('stop-color', vColor || 'rgba(2,135,188,0.5)')
.attr('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idT7EiCV6PyNW6q78o2He0P8DTEweItrFFIYAAAAASUVORK5CYII=';
svg.append('image')
.attr('width', 100)
.attr('height', 100)
.attr('x', 0)
.attr('y', 0)
.attr('xlink:href', imgSrc);
var data = [value, 100 - value];//圆环的数据
var pie = d3.pie()
.startAngle(0)
.sort(function(d, i) {
return d == value ? 1 : -1;
})
.endAngle(-Math.PI * 2);
var arcData = pie(data);//生成圆环数据的数组对象
var arc = d3.arc()
.innerRadius(39)
.outerRadius(50);
//.cornerRadius(6);
var group = svg.append('g')
.attr('transform', 'translate(50, 50)');
group.selectAll('path')
.data([arcData[0]])
.enter()
.append('path')
.attr('class','path' + vId)
.style('fill', 'rgba(0,0,0,0)')
.attr('d', arc);
var i = 0;
function move(){
if(i < 100){
requestAnimationFrame(move);
}else {
return;
}
$('.path' + vId).remove();//每次生成的时候要先删除原来的元素
i+=1;
data = [value * i / 100, 100 - value * i / 100];
pie = d3.pie()
.startAngle(0)
.sort(function(d, k) {
return d == value * i / 100 ? 1 : -1;
})
.endAngle(-Math.PI * 2);
arcData = pie(data);
group.selectAll('path')
.data([arcData[0]])
.enter()
.append('path')
.attr('class','path' + vId)
.style('fill', 'url(#' + id + ')')
.attr('d', arc);
text.text(value * i / 100 + '%')
}
var text = group.append('text')
.text(value + '%')
.attr('class','cirtext')
.attr('x', '0')
.attr('y', '0')
.attr('text-anchor', 'middle')
.attr('dy', '0.5em')
.style('fill', '#ffffff')
.style('cursor', 'pointer')
.style('font-size', 27);
move();
$('.cirtext').hover(function(){
$(this).css('transform','scale(1.2)')
},function(){
$(this).css('transform','scale(1)')
});
}
</script>
</html>
svg圆环缓冲动画的更多相关文章
- 纯CSS实现帅气的SVG路径描边动画效果(转载)
本文转载自: 纯CSS实现帅气的SVG路径描边动画效果
- SVG的路径动画效果
使用SVG animateMotion实现的一个动画路径效果,相关代码如下. 在线调试唯一地址:http://www.gbtags.com/gb/debug/c88f4099-5056-4ad7-af ...
- JavaScript原生折叠扩展收缩菜单带缓冲动画
JavaScript原生折叠扩展收缩菜单带缓冲动画 @落雨 <div id="div_two" style="display: none;"> &l ...
- 超级强大的SVG SMIL animation动画详解
本文花费精力惊人,具有先驱前瞻性,转载规则以及申明见文末,当心予以追究.本文地址:http://www.zhangxinxu.com/wordpress/?p=4333 //zxx: 本文的SVG在有 ...
- javascript动画效果之缓冲动画(修改版)
在编写多块同时触发运动的时候,发现一个BUG, timer = setInterval(show, 30);本来show是一个自定义函数,当设为timer = setInterval(show(one ...
- 快速找到自己想要用到的cocos2d-x的缓冲动画
游戏中在做很多动画时,需要用到缓冲来增强表现.比如宝箱"鼓"几下,然后"蹦"的一下打开.很多时候要调效果时,需要轮着试,如果有一张图和实际示例效果,那就省很多事 ...
- [转]超级强大的SVG SMIL animation动画详解
超级强大的SVG SMIL animation动画详解 本文花费精力惊人,具有先驱前瞻性,转载规则以及申明见文末,当心予以追究.本文地址:http://www.zhangxinxu.com/wordp ...
- 第165天:canvas绘制圆环旋转动画
canvas绘制圆环旋转动画——面向对象版 1.HTML 注意引入Konva.js库 <!DOCTYPE html> <html lang="en"> &l ...
- Expression Blend实例中文教程(10) - 缓冲动画快速入门Easing
随着Rich Internet application(RIA)应用技术的发展,各个公司越来越注重于项目的用户体验性,在保证其功能完善,运行稳定的基础上,绚丽的UI和人性化的操作设计会给用户带来舒适的 ...
随机推荐
- linux网络配置 转
1.常用配置网络指令 (1) 配置eth0的IP地址, 同时激活该设备 1 sudo ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up (2) 添 ...
- MATLAB GUI 设计要点 转
https://www.cnblogs.com/wangh0802PositiveANDupward/p/4588512.html 从简单的例子说起吧. 创建Matlab GUI界面通常有两种方式: ...
- 对malloc与free函数的浅识
本文介绍malloc和free函数的内容. 在C中,对内存的管理是相当重要.下面开始介绍这两个函数: 一.malloc()和free()的基本概念以及基本用法: .函数原型及说明: void *mal ...
- Android 如何使edittext默认失去焦点
1.在布局文件中给edittext的父控件增加两个属性 android:focusable="true" android:focusableInTouchMode="tr ...
- Map集合类(二.其他map集合jdk1.8)
java集合笔记一 java集合笔记二 java集合笔记三 1.hashtable(线程安全) 1.存储数据为数组+链表2.存储键值对或获取时通过hash值取模数组长度确定节点在数组中的下标位置 in ...
- php操作redis--集合(set)篇
常用函数:sAdd,sMembers,sPop,sUnion等 应用场景:与list类型类似,是一个列表的功能,不同的是set可以自动排重,提供了一个判断某一个成员是否存在一个set集合内的重要接口. ...
- 转:C++ 智能指针的正确使用方式
转:https://www.cyhone.com/articles/right-way-to-use-cpp-smart-pointer/#comments C++11 中推出了三种智能指针,uniq ...
- 30分钟全方位了解阿里云Elasticsearch
摘要:阿里云Elasticsearch提供100%兼容开源Elasticsearch的功能,以及Security.Machine Learning.Graph.APM等商业功能,致力于数据分析.数据搜 ...
- Android中的gen文件为空或者不存在的处理方法
Android中的gen文件时链接程序和XML中资源定义的桥梁,所以如果gen文件夹为空可能有以下的几个原因: 1.XML文件错误,这时可以检查res文件夹中的文件是否有错误 2.导入新的Androi ...
- 使用pangolin库画出轨迹
https://github.com/stevenlovegrove/Pangolin cmake_minimum_required(VERSION 2.8) project(chapter3) ) ...