Vue画线

作者: 洃冭鎯oo | 来源:发表于2021-12-24 19:06 被阅读0次
    <canvas id="canvas" width="400" height="400" style="border: 1px solid #ccc;"></canvas>
                // 画线并在线中间展示内容
                // let canvas = this.$ref.canvas
                // let cavParam = canvas.getContext('2d')
                setAndPoint(cavParam, txt, fromX, fromY, toX, toY, color, lineWidth) {
                    cavParam.beginPath();
                    cavParam.moveTo(fromX, fromY);
                    cavParam.lineTo(toX, toY);
                    cavParam.lineWidth = lineWidth
                    let plusOrMinus = Math.random() < 0.5 ? -1 : 1
                    let textPosition = {
                        x: (fromX + toX) / 2 + parseInt(Math.random() * 25 + 1) * plusOrMinus,
                        y: (fromY + toY) / 2 + parseInt(Math.random() * 25 + 1) * plusOrMinus,
                    }
                    cavParam.font = "16px"
                    cavParam.strokeStyle = color
                    cavParam.fillText(txt, textPosition.x, textPosition.y)
                    cavParam.beginPath();
                },
    

    相关文章

      网友评论

          本文标题:Vue画线

          本文链接:https://www.haomeiwen.com/subject/qnqrqrtx.html