如何获取HTML5画布的宽度和高度? [英] How do I get the width and height of a HTML5 canvas?
问题描述
如何在JavaScript中获取canvas元素的宽度和高度?
此外,我继续阅读的画布的上下文是什么? / p>
这可能值得一看教程: 您可以通过访问canvas元素的宽度和高度来获取canvas元素的宽度和高度。属性的元素。例如: 上下文是从画布中获取的一个对象, > How can i get the width and height of the canvas element in JavaScript? Also, what is the "context" of the canvas I keep reading about? It might be worth looking at a tutorial: Firefox Canvas Tutorial You can get the width and height of a canvas element simply by accessing those properties of the element. For example: The context is an object you get from the canvas to allow you to draw into it. 这篇关于如何获取HTML5画布的宽度和高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
var canvas = document.getElementById('mycanvas');
var width = canvas.width;
var height = canvas.height;
var canvas = document.getElementById('mycanvas');
var width = canvas.width;
var height = canvas.height;