2022-02-25 10:04:51
0
主代码页,示例代码:
- /*index.nml*/
- <div class="container">
- <div class="canvas-container">
- <canvas ref="ref_canvas" class="canvas" id="canvasId"/>
- </div>
- </div>
- /*index.css*/
- .container {
- flex-direction: column;
- justify-content: center;
- align-items: center;
- height: 100%;
- /* background-color: #5e7c85;*/
- }
- .canvas-container {
- flex-direction: column;
- justify-content: center;
- align-items: center;
- height: 100%;
- width: 100%;
- }
- .canvas {
- width: 340px;
- height: 340px;
- justify-content: center;
- align-items: center;
- align-content: center;
- margin-left: 10px;
- margin-right: 10px;
- }
- @keyframes rotateAnim {
- from {
- transform: rotate(0deg);
- }
- to {
- transform: rotate(360deg);
- }
- }
- #canvasId {
- animation: rotateAnim 5s 0s linear infinite;
- }
- /*index.js*/
- export default {
- data: {},
- onShow() {
- this.draw(170, 170);
- },
- draw(x, y) {
- const el = this.$refs.ref_canvas;
- var ctx = el.getContext('2d', {
- antialias: true
- });
- //半径
- let radius = 150;
- ctx.beginPath();
- ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
- ctx.stroke();
- ctx.fillStyle = 'black';
- ctx.beginPath();
- ctx.moveTo(x, y - radius);
- ctx.bezierCurveTo(x - radius, y - radius / 2, x + radius, y + radius / 2, x, y + radius);
- ctx.arc(x, y, radius, -(Math.PI / 180) * 270, (Math.PI / 180) * 270, true);
- ctx.closePath();
- ctx.fill();
- ctx.beginPath();
- ctx.arc(x, y + radius / 2, 20, 0, 2 * Math.PI, false);
- ctx.fill();
- ctx.fillStyle = 'white';
- ctx.beginPath();
- ctx.arc(x, y + -radius / 2, 20, 0, 2 * Math.PI, false);
- ctx.fill();
- }
- }
复制代码
案例效果:
附件:
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容图片侵权或者其他问题,请联系本站作侵删。
侵权投诉