为什么我修改不了canvas画布大小

来源:1-2 绘制米字格,复习canvas

BuFang_Q

2016-02-13 21:42

html文件代码

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head lang = "en">

<meta  charset=utf-8" />

    <title>121212</title>

    <script src="jquery-2.1.3.min.js" type = "text/javascript"></script>

    <link href="handwriting.css" rel="stylesheet" type="text/css"/>

</head>


<body>


<canvas id="canvas">

    您的浏览器不支持canvas

    </canvas>

<script src = "handwriting.js"></script>

</body>

</html>


JS文件代码:

var canvasWidth = 800

var canvasHeight = canvasWidth


var canvas = document.getElementById("canvas")[0]

var context = convas.getContext('2d')


canvas.width = canvasWidth

canvas.height = canvasHeight


写回答 关注

2回答

  • 问天012
    2016-04-14 11:32:23

    var canvas = document.getElementById("canvas")[0]这里要加[0]么?


    湛瞳

    不需要,id的名字是唯一的

    2016-09-23 10:41:40

    共 1 条回复 >

  • 慕慕7149077
    2016-02-14 22:28:46

    var canvasWidth=Math.min(800,$(window).width()-20);

学写一个字

canvas系列第四课,与鼠标、触控交互,学习写出一个字

70879 学习 · 52 问题

查看课程

相似问题