zoukankan      html  css  js  c++  java
  • canvas制作圆形动态加载进度实例

    window.onload=function(){
    	var loading=document.getElementById('loading');
    	var context=loading.getContext('2d');
    	var num=parseInt(Math.random()*100)/100;//模拟获取进度值
    	var temp=0;//当前进度值
    	var time=1000;//动画总时长
    	var step=1000*0.01/num;//动画步长
    	function loadanimate(){
    		context.beginPath();
    		context.arc(150,150,150,0,2*Math.PI);
    		context.fillStyle='#ccc';
    		context.fill();
    		context.beginPath();
    		context.arc(150,150,130,0,2*Math.PI);
    		context.fillStyle='#fff';
    		context.fill();
    		context.fillStyle='#ccc';
    		context.font="110px 微软雅黑 ";
    		if(temp>0.09){//调整文本居中
    			context.fillText(parseInt(temp*100)+"%",45,188);
    		}else{
    			context.fillText(" "+parseInt(temp*100)+"%",45,188);
    		}
    		context.save();
    		
    		context.beginPath();
    		context.rect(0,300*(1-temp),300,300*temp);
    		context.clip();
    		
    		context.beginPath();
    		context.arc(150,150,150,0,2*Math.PI);
    		context.fillStyle='aquamarine';
    		context.fill();
    		context.beginPath();
    		context.arc(150,150,130,0,2*Math.PI);
    		context.fillStyle='#fff';
    		context.fill();
    		context.fillStyle='aquamarine';
    		context.font="110px 微软雅黑 ";
    		if(temp>0.09){
    			context.fillText(parseInt(temp*100)+"%",45,188);
    		}else{
    			context.fillText(" "+parseInt(temp*100)+"%",45,188);
    		}
    		context.restore();
    		setTimeout(function(){
    			if(num>temp){
    				temp+=0.01;
    				loadanimate();
    			}
    		},step);
    	}
    	loadanimate();
    };
     
    

      

  • 相关阅读:
    charles安装以及手机端的设置
    ON DUPLICATE KEY UPDATE 用法与说明
    亿级流量架构之网关设计思路、常见网关对比
    灰度发布系统架构设计
    Jmeter 并发测试
    springboot --- Swagger UI初识
    TortoiseGIT 一直提示输入密码的解决方法!
    MySQL 5.6 参数详解
    LVS 轮询调度详解
    MongoDB 权限
  • 原文地址:https://www.cnblogs.com/goodbeypeterpan/p/9686485.html
Copyright © 2011-2022 走看看