Long time no move canvas, this afternoon suddenly want to review, wrote a rotation of Tai chi, haha, quite fun, in here will write their own process to show out, rotate the use of CSS implementation, not with canvas their own, I hope the big boys do not spit groove. This article mainly introduces the data of the example of canvas making rotating taiji, hoping to help everyone.
Objective
Css
body{ background: #ddd;} #canvas { position:absolute; left:40%; top:30%; -webkit-transform:translate ( -50%,-50%); -moz-transform:translate ( -50%,-50%); -ms-transform:translate ( -50%,-50%); -o-transform:translate ( -50%,-50%); Transform:translate ( -50%,-50%); -webkit-animation:testanimate 3s linear infinite; -o-animation:testanimate 3s linear infinite; Animation:testanimate 3s linear infinite;} @keyframes Testanimate {from { -webkit-transform:rotate (0); -moz-transform:rotate (0); -ms-transform:rotate (0); -o-transform:rotate (0); Transform:rotate (0); } to { -webkit-transform:rotate (360deg); -moz-transform:rotate (360deg); -ms-transform:rotate (360deg); -o-transform:rotate (360deg); Transform:rotate (360deg); }}
Html
<body> <canvas id= "Canvas" width= "height=" ></canvas></body>
Js
Let CTX = document . getElementById ("Canvas") . GetContext ("2d");//Left-black-bigctx.beginpath (); Ctx.fillstyle = "#000"; Ctx.arc (250,250,200,math.pi/2,math.pi*1.5,false); Ctx.closepath (); Ctx.fill ();// Right-white-bigctx.beginpath (); ctx.fillstyle = "#fff"; Ctx.arc (250,250,200,math.pi/2,math.pi*1.5,true); Ctx.closepath (); Ctx.fill ();//Top-black-middlectx.beginpath (); ctx.fillstyle = "#000"; Ctx.arc (250,150,100,math.pi/ 2,math.pi*1.5,true); Ctx.closepath (); Ctx.fill ();//Bottom-white-middlectx.beginpath (); ctx.fillstyle = "#fff"; Ctx.arc (250,350,100,math.pi/2,math.pi*1.5,false); Ctx.closepath (); Ctx.fill ();//Top-white-smallctx.beginpath (); Ctx.fillstyle = "#fff"; Ctx.arc (250,150,25,0,math.pi*2); Ctx.closepath (); Ctx.fill ();// Bottom-black-smallctx.beginpath (); ctx.fillstyle = "#000"; Ctx.arc (250,350,25,0,math.pi*2); Ctx.closepath (); Ctx.fill ();
Effect