Created
September 30, 2011 13:02
-
-
Save Victa/1253680 to your computer and use it in GitHub Desktop.
Canvas Spinner
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> | |
<title>Canvas spinner</title> | |
<link rel=stylesheet href=s.css> | |
<script src=s.js></script> |
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
#spinner { | |
position:absolute; | |
left:50%; | |
top:45%; | |
margin-left:-8px; | |
} |
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
window.onload = function(){ | |
var canvas = document.createElement("canvas"), | |
ctx = canvas.getContext("2d"), | |
size = 16, | |
bars = 12; | |
canvas.id = "spinner"; | |
canvas.width = size; | |
canvas.height = size; | |
document.body.appendChild(canvas); | |
ctx.translate(size/2,size/2); | |
setInterval(function(){ | |
ctx.clearRect(-size/2,-size/2,size,size); | |
ctx.rotate(Math.PI*2/bars); | |
for (var i=0; i<bars; i++) { | |
ctx.rotate(Math.PI*2/bars); | |
ctx.strokeStyle = "rgba(0,0,0," + i/bars + ")"; | |
ctx.beginPath(); | |
ctx.moveTo(0,size/4); | |
ctx.lineTo(0,size/2); | |
ctx.stroke(); | |
} | |
}, 60); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By BDC http://playground.deaxon.com/js/canvas-spinner/