如何用js新建一个canvas?
我在html中是这样写的<divid="lineArea"></div>然后想动态地往这个div里面加入一个canvas元素,于是我在script中是这样写的:varca...
我在html中是这样写的
<div id="lineArea"></div>
然后想动态地往这个div里面加入一个canvas元素,于是我在script中是这样写的:
var canvasList = document.getElementById('lineArea');
var canvas = document.createElement('canvas');
canvasList.appendChild(canvas);
canvas.width = '1000px';
canvas.height = '500px';
canvas.style.backgroundColor = '#FF0000';
但是这样并不会画出来。那么请问要怎样做才能动态地添加canvas呢? 展开
<div id="lineArea"></div>
然后想动态地往这个div里面加入一个canvas元素,于是我在script中是这样写的:
var canvasList = document.getElementById('lineArea');
var canvas = document.createElement('canvas');
canvasList.appendChild(canvas);
canvas.width = '1000px';
canvas.height = '500px';
canvas.style.backgroundColor = '#FF0000';
但是这样并不会画出来。那么请问要怎样做才能动态地添加canvas呢? 展开
2个回答
2016-01-27 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
用js新建canvas的方法如下:
var canvas = document.createElement('canvas');
canvas.id = "CursorLayer";
canvas.width = 1224;
canvas.height = 768;
canvas.style.zIndex = 8;
canvas.style.position = "absolute";
canvas.style.border = "1px solid";
document.body.appendChild(canvas);
注意:此处一定要追加到body里面。
var canvas = document.createElement('canvas');
canvas.id = "CursorLayer";
canvas.width = 1224;
canvas.height = 768;
canvas.style.zIndex = 8;
canvas.style.position = "absolute";
canvas.style.border = "1px solid";
document.body.appendChild(canvas);
注意:此处一定要追加到body里面。
2015-07-24
展开全部
<html>
<head>
<title></title>
</head>
<body>
<div id="lineArea"></div>
<script type="text/javascript">
var canvasList = document.getElementById('lineArea');
var canvas = document.createElement('canvas');
canvasList.appendChild(canvas);
canvas.width = 1000; //☜
canvas.height = 500;
canvas.style.backgroundColor = '#FF0000';
</script>
</body>
</html>
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询