为了账号安全,请及时绑定邮箱和手机立即绑定

不能实现在canvas中插入canvas

<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
    <canvas id="canvas" style="border:1px solid red;display:block;margin:50px auto;">
    </canvas>
    <script>
        window.onload=function(){
            var canvas=document.getElementById("canvas");
            canvas.width=800;
            canvas.height=800;
            var context=canvas.getContext("2d");
            var backCanvas=createBackgroundCanvas();
            var pattern=context.createPattern(backCanvas,"repeat");
            context.fillStyle=pattern;
            context.fillRect(0,0,800,800);
       }
            function createBackgroundCanvas(){
            var backCanvas=document.createElement("canvas");
            var backCanvas.width=100;
            var backCanvas.height=100;
            var backCanvasContext=backCanvas.getContext("2d");
            backCanvasContext.beginPath();
            backCanvasContext.moveTo(15,15);
            backCanvasContext.lineTo(50,50);
            backCanvasContext.lineWidth=10;
            backCanvasContextt.strokeStyle="green"
            backCanvasContext.stroke();
            return backCanvas;
            }
            
        
    </script>
</body>
</html>


正在回答

2 回答

问题一大堆,首先backCanvas声明一个就行了 声明这么多干嘛,还有backCanvasContextt.strokeStyle="green"都输入错了

function createBackgroundCanvas(){

            var backCanvas=document.createElement("canvas");

            backCanvas.width=100;

            backCanvas.height=100;

            backCanvasContext=backCanvas.getContext("2d");

            backCanvasContext.beginPath();

            backCanvasContext.moveTo(15,15);

            backCanvasContext.lineTo(50,50);

            backCanvasContext.lineWidth=10;

            backCanvasContext.strokeStyle="green";

            backCanvasContext.stroke();

            return backCanvas;

            }


0 回复 有任何疑惑可以回复我~

我也想问这个问题!!

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Canvas绘图详解
  • 参与学习       72895    人
  • 解答问题       422    个

Canvas系列教程第二课,详解Canvas各接口,让同学彻底掌握Canvas绘图

进入课程

不能实现在canvas中插入canvas

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信