环形效果

简介: 环形效果是不是相当的诱人,首先看几个例子:1、colorful-clock  --- 漂亮2、CSS3+js实现多彩炫酷旋转圆环时钟效果  --- very good3、Percentage Loader  --- 帅colorful-clock效果图如下:有没有更刺激的,接下来见证奇迹的时刻,如下图(精致):在此之前,在回顾下前两个例子:1、时钟效果_raphael.

环形效果是不是相当的诱人,首先看几个例子:
1、colorful-clock  --- 漂亮
2、CSS3+js实现多彩炫酷旋转圆环时钟效果  --- very good
3、Percentage Loader  --- 帅

colorful-clock效果图如下:



有没有更刺激的,接下来见证奇迹的时刻,如下图(精致):



在此之前,在回顾下前两个例子:
1、时钟效果_raphael.js
2、幸运大抽奖



实现原理:
第一步:构造圆环

r.customAttributes.arc = function(value, total, R) {
    var alpha = 360 / total * value,
        a = (90 - alpha) * Math.PI / 180,
        x = 150 + R * Math.cos(a),
        y = 150 - R * Math.sin(a),
        path;
    if (total == value) {
        path = [
            ["M", 150, 150 - R],
            ["A", R, R, 0, 1, 1, 149.99, 150 - R]
        ];
    } else {
        path = [
            ["M", 150, 150 - R],
            ["A", R, R, 0, +(alpha > 180), 1, x, y]
        ];
    }
    bpath = path;
    return {
        path: path
    };
};
r.path().attr({
    arc: [100, 100, rad],
    'stroke-width': 20,
    'stroke': "#cecece"
});


第二步:环形动起来和事件绑定

function updateVal(value, total, R, hand, id) { 
    if (init) {
        hand.animate({
            arc: [value, total, R]
        }, 900, ">");
    } else {
        if (!value || value == total) {
            value = total;
            hand.animate({
                arc: [value, total, R]
            }, 750, "bounce", function() {
                hand.attr({
                    arc: [0, total, R]
                });
            });
        } else {
            hand.animate({
                arc: [value, total, R]
            }, 750, "elastic");
        }
    }
};
z.mouseover(function() {
    this.animate({
        'stroke-width': 36,
        opacity: 0.75
    }, 600, 'elastic');
}).mouseout(function() {
    this.stop().animate({
        'stroke-width': 26,
        opacity: 1
    }, speed * 4, 'elastic');
});


第三步:倒计时

function dinit() {
    if (tmptime > 0) {
        ds = parseInt(tmptime % 60);
        dm = parseInt(tmptime / 60) % 60;
        dh = parseInt(tmptime / 3600) % 24;

        txt.remove();
        txt = r.text(150, 150, dh + ":" + dm + ":" + ds).attr({
            font: "100 36px Arial",
            fill: opts.color
        });
    }
};

function playing() {
    dstop = setInterval(function() {
        tmptime--;
        if (tmptime <= 1) { !! opts.endSucc && opts.endSucc();
            clearInterval(dstop);
        } else {
            dinit();
        }
    }, 1000);
};


搞定,大功告成。感兴趣的可以动手试试,写更fashion的效果,期待你的见证。



参考:
polar-clock
CSS3+JS动态圆形图例jquery代码



DEMO:

<!doctype html> <html lang="cn"> <head> <meta charset="UTF-8"> <title>环形</title> <style> *{margin:0px;padding: 0px;} body{padding: 0px 0px 300px;} .main{width: 960px; margin: 0px auto;overflow: hidden;} .mainTit{color: #f00; font-size: 50px;font-weight:bold;text-align: center; text-shadow: 3px 1px 6px #f60; padding: 10px 0px;} .mainBlock{overflow: hidden;} .main .block{float: left; width: 300px; height: 300px; margin: 0px 10px; overflow: hidden;} .main .block div{width: 100%; height: 100%; } .main .remark{color: #333;font-size: 12px; text-align: center; margin-top: 10px;} </style> </head> <body> <div class="main"> <div class="mainTit">环形</div> <div class="mainBlock"> <div class="block"><div id="test1"></div></div> <div class="block"><div id="test2"></div></div> <div class="block"><div id="test3"></div></div> <div class="block"><div id="test4"></div></div> <div class="block"><div id="test5"></div></div> <div class="block"><div id="test6"></div></div> </div> </div> <script src="http://files.cnblogs.com/kuikui/jquery-1.10.2.min.js"></script> <script src="http://files.cnblogs.com/kuikui/raphael.js"></script> <script type="text/javascript"> (function($) { $.drawCircle = function(options) { var defaults = { elem: null, size: 0, start: null, end: null, endSucc: null }; var opts = $.extend({}, defaults, options); if (!opts.elem) { return; } var r = Raphael(opts.elem, 300, 300), rad = 80, init = true, speed = 200, z = null, txt = null; var tmptime = opts.end - opts.start, ds = null, dm = null, dh = null, dstop = null; if (opts.size === 0) { opts.color = "#cecece"; } else { opts.color = getColor(opts.size) || "#000000"; } function minit() { r.customAttributes.arc = function(value, total, R) { var alpha = 360 / total * value, a = (90 - alpha) * Math.PI / 180, x = 150 + R * Math.cos(a), y = 150 - R * Math.sin(a), path; if (total == value) { path = [ ["M", 150, 150 - R], ["A", R, R, 0, 1, 1, 149.99, 150 - R] ]; } else { path = [ ["M", 150, 150 - R], ["A", R, R, 0, +(alpha > 180), 1, x, y] ]; } bpath = path; return { path: path }; }; r.path().attr({ arc: [100, 100, rad], 'stroke-width': 20, 'stroke': "#cecece" }); r.path().attr({ arc: [100, 100, 110], 'stroke-width': 2, 'stroke': "#cecece" }); if(!!opts.size){ z = r.path().attr({ arc: [0.01, 100, rad], 'stroke-width': 20, 'stroke': opts.color, 'cursor': "pointer" }); updateVal(opts.size, 100, 80, z, 2); } var circle = r.circle(150, 150, 70); circle.attr("fill", "#fff"); circle.attr("stroke", "none"); circle.glow({ width: 8, opacity: 0.3, offsety: 4 }); txt = r.text(150, 150, opts.size + "%").attr({ font: "100 36px Arial", fill: opts.color }); }; function dinit() { if (tmptime > 0) { ds = parseInt(tmptime % 60); dm = parseInt(tmptime / 60) % 60; dh = parseInt(tmptime / 3600) % 24; txt.remove(); txt = r.text(150, 150, dh + ":" + dm + ":" + ds).attr({ font: "100 36px Arial", fill: opts.color }); // txt.toFront(); } }; function playing() { dstop = setInterval(function() { tmptime--; if (tmptime <= 1) { !! opts.endSucc && opts.endSucc(); clearInterval(dstop); } else { dinit(); } }, 1000); }; function getColor(size) { var arr = []; for (var i = 0; i <= 255; i++) { arr.push("rgb(" + i + "," + (255 - i) + ","+0+")"); } return arr[parseInt(size * 2.55)]; }; function updateVal(value, total, R, hand, id) { if (init) { hand.animate({ arc: [value, total, R] }, 900, ">"); } else { if (!value || value == total) { value = total; hand.animate({ arc: [value, total, R] }, 750, "bounce", function() { hand.attr({ arc: [0, total, R] }); }); } else { hand.animate({ arc: [value, total, R] }, 750, "elastic"); } } }; function mevents() { if(!!opts.size){ z.mouseover(function() { this.animate({ 'stroke-width': 36, opacity: 0.75 }, 600, 'elastic'); //txt.toFront(); }).mouseout(function() { this.stop().animate({ 'stroke-width': 26, opacity: 1 }, speed * 4, 'elastic'); }); } }; minit(); dinit(); playing(); mevents(); }; })(jQuery); $(function() { $.drawCircle({ elem: "test1", size: 0, start: 0, end: 6600 }); $.drawCircle({ elem: "test2", size: 0 }); $.drawCircle({ elem: "test3", size: 25 }); $.drawCircle({ elem: "test4", size: 55 }); $.drawCircle({ elem: "test5", size: 85 }); $.drawCircle({ elem: "test6", size: 100 }); }); </script> </body> </html>

目录
相关文章
|
存储 域名解析 负载均衡
负载均衡是什么,负载均衡有什么作用
负载均衡是什么,负载均衡有什么作用
|
人工智能 边缘计算 自然语言处理
大模型应用实践:2025年智能语音机器人厂商推荐和方案详解
随着数字化转型加速,AI客服机器人市场规模预计2025年突破500亿美元,年复合增长率超25%。其发展由语音交互升级、垂直场景解决方案成熟及多模态融合与边缘计算普及三大趋势驱动。文章分析了智能语音机器人的选型核心维度,包括技术性能、场景适配、数据治理与成本效益,并对比了国内外代表厂商如合力亿捷、Zendesk等的方案特点,为企业提供选型策略与落地建议,助力实现服务模式的根本性变革。
1491 0
|
存储 人工智能 数据可视化
2025年技术团队必看:10款提升研发效率的知识管理工具深度评测
在数字化时代,知识管理已成为提升个人与企业竞争力的关键。2025年,随着AI、大数据和云计算的发展,知识管理工具正向智能化、协作化方向演进。本文精选10款必备工具,涵盖Notion、Obsidian、语雀、飞书文档等,助你构建高效知识体系,把握未来趋势。
1744 0
|
Dart IDE 开发工具
Flutter 图文并茂列表实现
Flutter使用 ListView 完成列表的构建,界面实现的关键工作实际是布局子元素的拆分。剩下的实现方式存在多种,看各人喜好。但是,需要注意避免过多嵌套导致代码不好维护,并需要提高复用性。
1252 2
Flutter 图文并茂列表实现
|
人工智能 缓存 运维
ACK计费相关概念
ACK计费相关概念
288 4
|
存储 算法 对象存储
MindOpt Tuner调参器,提升求解速度、性能(一)
优化求解器往往拥有很多配置参数,例如启发式方法的开关、割平面方法的开关、预处理的配置以及各种误差容忍度等等。MindOpt Tuner会尝试不同的参数组合,评估每组参数的性能,然后基于这些结果来确定最佳参数。这样可以大大减少手动调整参数的时间和精力,并且可以帮助提升求解性能。
MindOpt Tuner调参器,提升求解速度、性能(一)
|
Prometheus 监控 Oracle
oracledb_exporter监控Oracle,一个入侵性极低的监控方案。
oracledb_exporter监控Oracle,一个入侵性极低的监控方案。
1550 0
|
缓存 NoSQL 数据库
一文搞懂秒杀系统,欢迎参与开源,提交PR,提高竞争力。
一文搞懂秒杀系统,欢迎参与开源,提交PR,提高竞争力。
543 0
|
数据可视化 前端开发