如何获取HTML5画布的宽度和高度? [英] How do I get the width and height of a HTML5 canvas?

查看:129
本文介绍了如何获取HTML5画布的宽度和高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在JavaScript中获取canvas元素的宽度和高度?



此外,我继续阅读的画布的上下文是什么? / p>

解决方案

这可能值得一看教程:

您可以通过访问canvas元素的宽度和高度来获取canvas元素的宽度和高度。属性的元素。例如:

  var canvas = document.getElementById('mycanvas'); 
var width = canvas.width;
var height = canvas.height;

上下文是从画布中获取的一个对象, >

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:

var canvas = document.getElementById('mycanvas');
var width = canvas.width;
var height = canvas.height;

The context is an object you get from the canvas to allow you to draw into it.

这篇关于如何获取HTML5画布的宽度和高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆