HTML <canvas> width 属性
标签" href="tag-main.html"><main>
<map>
<mark>
<menu>
<meta>
<meter>
<nav>
<noframes>
<noscript>
<object>
<ol>
<optgroup>
<option>
<output>
<p>
<param>
<pre>
<html>
<picture>
<progress>
<q>
<rp>
<rt>
<ruby>
<s>
<samp>
<script>
<section>
<select>
<small>
<source>
<span>
<strike>
<strong>
<style>
<sub>
<summary>
<sup>
<table>
<tbody>
<td>
<textarea>
< template>
<tfoot>
<th>
<thead>
<time>
<title>
<tr>
<track>
<tt>
<u>
<ul>
<var>
<video>
<wbr>
HTML <canvas> width 属性
实例
高度和宽度为200像素的 <canvas> 元素:
<canvas id="myCanvas" width="200" height="200" style="border:1px solid">
浏览器支持
所有主流浏览器都支持 width 属性。
注意: Internet Explorer 8 及更早IE版本不支持 <canvas> 标签。
定义和用法
width 属性返回 ImageData 对象的宽度,以像素计。
提示: 每当画布的高度或宽度被重设时,画布内容就会被清空(请看页面底部的例子)。
提示: 请在我们的 HTML Canvas 教程中学习更多有关 <canvas>的知识。
HTML 4.01 与 HTML 5 之间的差异
<canvas> 是 HTML5 中的新标签。
语法
<canvas width="pixels">
属性值
| Value | Description |
|---|---|
| pixels | 指定 canvas 的 width属性, 以像素计(如"100")。 默认 width 为 "300" |
更多实例
清空画布
如何通过重设 width 或 height 属性来清空画布(使用 JavaScript)。