Canvas制作旋转太极的动画

广告:宝塔Linux面板高效运维的服务器管理软件 点击【 https://www.bt.cn/p/uNLv1L 】立即购买

Canvas制作旋转太极的动画

这次给大家带来Canvas制作旋转太极的动画,Canvas制作旋转太极动画的注意事项有哪些,下面就是实战案例,一起来看一下。

前言

好久没动canvas了,今下午突然想回顾一下,就写了个旋转的太极,哈哈,蛮好玩的,在这里就将自己写的过程展示出来,旋转使用的css实现的,没有用canvas自己的,希望大佬们不要吐槽。

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="500" height="500"></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();
登录后复制

效果

相信看了本文案例你已经掌握了方法,更多精彩请关注9543建站博客其它相关文章!

推荐阅读:

H5中APP监听返回事件处理

h5实现多图片预览上传及点击可拖拽控件

以上就是Canvas制作旋转太极的动画的详细内容,更多请关注9543建站博客其它相关文章!

广告:SSL证书一年128.66元起,点击购买~~~

9543建站博客
一个专注于网站开发、微信开发的技术类纯净博客。

作者头像
admin创始人

肥猫,知名SEO博客站长,14年SEO经验。

上一篇:css怎么设置td的宽度
下一篇:HTML5特殊符号怎么显示

发表评论

关闭广告
关闭广告