jquery写的一个圆形动画加载进度条
2016-02-04 10:40
495 查看
<!DOCTYPE html> <html xmlns=" http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Canvas绘图</title> <script src=" http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> </head> <body> <canvas class="process" width="<span style="color:#FF0000;">200px</span>" height="<span style="color:#FF0000;">200px</span>">0%</canvas> </body> <script> $(document).ready(function() { //drawProcess(); i = 0; var t = setInterval("addNum(90,100)",20); }); function addNum(percent,width) { if(i<percent){ i++; $('canvas.process').text(i+"%"); drawProcess(width); }else{ clearInterval(t); } } function drawProcess(width) { $('canvas.process').each(function() { var text = $(this).text(); var process = text.substring(0, text.length-1); var canvas = this; var context = canvas.getContext('2d'); context.clearRect(0, 0, width, width); context.beginPath(); context.moveTo(width/2, width/2); context.arc(width/2, width/2, width/2, 0, Math.PI * 2, false); context.closePath(); context.fillStyle = '#ddd'; context.fill(); context.beginPath(); context.moveTo(width/2, width/2); context.arc(width/2, width/2, width/2, 0, Math.PI * 2 * process / 100, false); context.closePath(); context.fillStyle = '#2a2'; context.fill(); context.beginPath(); context.moveTo(width/2, width/2); context.arc(width/2, width/2, width/2 - 10, 0, Math.PI * 2, true); context.closePath(); context.fillStyle = 'rgba(255,255,255,1)'; context.fill(); context.beginPath(); context.arc(width/2, width/2, width/2 - 20, 0, Math.PI * 2, true); context.closePath(); context.strokeStyle = '#ddd'; context.stroke(); context.font = "bold 9pt Arial"; context.fillStyle = '#2a2'; context.textAlign = 'center'; context.textBaseline = 'middle'; context.moveTo(width/2, width/2); context.fillText(text, width/2, width/2); }); } </script> </html>
drawProcess()这个方法主要是画圆的大小,参数就是圆的宽度,而在上面的<canvas>中的宽度则不是准确的,主要看的是drawProcess(width)这里传的width
上面所写到的 setInterval("addNum(90,100)",20); 分别指的是:
1.这里的三个参数分别是90:在90%处
2.100:圆的宽度
3.20:2秒之后执行这个addNum方法
效果图:
而且他进入页面加载的时候是会进行动态滚动到90%的位置
相关文章推荐
- JQuery模拟点击click
- jQuery----blur()方法
- jquery的checkbox,radio,select等方法总结
- jquery复选框 选中事件 及其判断是否被选中
- jQuery原理系列-css选择器实现
- NET 利用 jquery+ztree 实现 角色权限设置(以树结构显示导航菜单)
- 【jQuery基础学习】09 jQuery与前端(这章很水)
- jQuery 中的 DOM 操作
- JQuery实现品牌展示
- jquery操作select元素和option的实例代码
- form表单的提交相关的jquery
- jQuery.fn.extend() jQuery.extend()
- Ajax的实现和jQuery下的Ajax
- jQuery - 编写jQuery插件的基本形式(下)
- jQuery插件地址汇总
- JQuery Autocomplete实战
- jquery 处理返回数据 html json xml
- input
- jQuery 操作列表批量删除数据
- jquery实现替代iframe的功能