Last active
August 26, 2016 08:37
-
-
Save alexzhou/7210181 to your computer and use it in GitHub Desktop.
使用canvas 画环形进度条
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>circle progressbar</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
var range = $('#range'); | |
var bg = $('#counter'); | |
var ctx = bg[0].getContext('2d'); | |
var imd = null; | |
var circ = Math.PI * 2; | |
var quart = Math.PI / 2; | |
ctx.beginPath(); | |
ctx.strokeStyle = '#99CC33'; | |
ctx.lineCap = 'square'; | |
ctx.closePath(); | |
ctx.fill(); | |
ctx.lineWidth = 10.0; | |
imd = ctx.getImageData(0, 0, 240, 240); | |
var draw = function(current) { | |
ctx.putImageData(imd, 0, 0); | |
ctx.beginPath(); | |
ctx.arc(120/*x*/, 120/*y*/, 70/*r*/, -(quart)/*起始弧度 12点位置*/, ((circ) * current) - quart/*结束位置*/, false/*顺时针*/);//画圆 | |
ctx.stroke(); | |
} | |
draw(range.val()/100); | |
range.mousemove(function(){ | |
draw(this.value/100); | |
}) | |
}) | |
</script> | |
</head> | |
<body> | |
<style type="text/css"> | |
canvas { | |
display: block; | |
} | |
input { | |
width: 200px; | |
} | |
body { | |
} | |
</style> | |
<input id="range" type="range" min="0" max="100" /> | |
<canvas id="counter" width="240" height="240"></canvas> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment