Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
画布html5/jquery/javascript模板_Javascript_Jquery_Html5 Canvas - Fatal编程技术网

画布html5/jquery/javascript模板

画布html5/jquery/javascript模板,javascript,jquery,html5-canvas,Javascript,Jquery,Html5 Canvas,我是HTML5、Jquery/JavaScript的初学者。 我正在尝试创建一个画布(有点像windows paint应用程序),我正在查看其他用户的示例函数/代码,看看它是怎么回事,并尝试重新创建它 $(function(){ var paint = new Paint($('#surface').get(0)); // Setup line template var templateLine = new Paint($('#toolbar #line').get(0), {'readonl

我是HTML5、Jquery/JavaScript的初学者。 我正在尝试创建一个画布(有点像windows paint应用程序),我正在查看其他用户的示例函数/代码,看看它是怎么回事,并尝试重新创建它

$(function(){
var paint = new Paint($('#surface').get(0));

// Setup line template
var templateLine = new Paint($('#toolbar #line').get(0), {'readonly': true});
templateLine.shape = new Line([10, 10], [50, 50]);
templateLine.place(templateLine.shape);
我不确定这里发生了什么。我知道这种新油漆不是内置功能。这是怎么一回事? 第二,这和我的有什么区别

$( document).ready(function(){
var canvas = $("#canvas").get(0);
if (canvas.getContext) {
        var ctx = canvas.getContext("2d");

        // Choose a color
        ctx.fillStyle = "black";
        ctx.strokeStyle = color;
        ctx.fillRect(0, 0, 50, 50);
    } else {
        // Browser doesn't support CANVAS
    }
});

救命啊

首先,您在问题开头看到的代码可能使用了一些画布库或API,但这并不是普通的HTML5画布API,这使得它与您在下面编写的完全不同,即使它们具有相同的输出(尽管看起来不像)

其次,
color
没有定义,所以除非在其他地方的代码中定义了颜色,否则代码将无法工作。否则,您的代码将在画布的角上绘制一个黑色矩形,笔划颜色为
color
的任何颜色