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和人性化的操作设计会给用户带来舒适的 ...
随机推荐
- Android Studio javadoc 生成注释文档
相信大家刚开始写代码的时候就被前辈告知了要养成写注释的好习惯,今天我们来了解一下如何利用我们平时写的注释生成文档,一起来看看吧! 其实注释格式一般如下两种: /* *普通多行 *注释 */ / ...
- macOS截屏
Command+Shift+3: 全屏幕截屏,并自动保存在桌面 Command+Shift+4: 手动截屏,并自动保存在桌面 Command+Shift+4, + Space, 之后点击程序的窗口,实 ...
- python判断文件的编码格式是否为UTF8 无BOM格式
转自: https://www.cnblogs.com/ferraborghini/p/4951102.html https://www.cnblogs.com/Detector/p/8744992. ...
- apue第4章习题
4.1 用 stat 函数替换图 4-3 程序中的 lstat函数,如若命令行残数之一是符号链接,会发生什么变化? stat不支持链接,如果有参数是链接符号,会显示链接后的文件属性. 4.2 如果文件 ...
- Java打war包or打jar包
//一个jar包可以包含多个entry,这样就能实现下面功能 1.I/O 读文件流步骤 File file=new File(filePath); ...
- TxtUtil
/** *包名:cn.yufu.utils *描述:package cn.yufu.utils; */ package cn.yufu.utils; import java.io.BufferedRe ...
- NOIP模拟测试18(T3待更新)
T1: 直接模拟,详见代码注释. 复杂度$O(NM)$. Code: #include<iostream> #include<cstdio> #include<vecto ...
- php网络编程实例
php网络编程实例 一.总结 一句话总结: socket_create():创建socket socket_bind():绑定IP和端口 socket_listen():监听客户端信息 <?ph ...
- mac下nginx
配置文件位置 /usr/local/etc/nginx/nginx.conf 简单命令 nginx -s quit 退出 nginx -s reload 重新加载 nginx -t 测试nginx.c ...
- git分布式版本控制系统权威指南学习笔记(一):配置文件、简单流程和小问题
文章目录 git配置文件简介 git config各种命令 配置级别: 用户信息 文本编辑器 差异分析工具 配置命令别名 公钥 git协同流程 简单流程 初始化版本库 提交至缓存区 查看状态 提交分支 ...