导航
×
   ❮   
HTML CSS JavaScript PHP Go Sass W3C Colors ECMS

HTML 参考手册

HTML 元素(功能排序) HTML 浏览器支持 HTML 属性 HTML 全局属性 HTML 事件 HTML 颜色 HTML 画布 HTML 音频/视频 HTML 字符集 HTML 文档类型 HTML URL 编码 HTML 语言代码 HTML 国家代码 HTTP 状态消息 HTTP 请求方法 PX-EM 转换 键盘快捷键

HTML 标签

<!--> <!DOCTYPE> <a> <abbr> <acronym> <address> <applet> <area> <article> <aside> <audio> <b> <base> <basefont> <bdi> <bdo> <big> <blockquote> <body> <br> <button> <canvas> <caption> <center> <cite> <code> <col> <colgroup> <data> <datalist> <dd> <del> <details> <dfn> <dialog> <dir> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <font> <footer> <form> <frame> <frameset> <h1> - <h6> <head> <header> <hr> <html> <i> <iframe> <img> <input> <ins> <kbd> <label> <legend> <li> <link> <main> <map> <mark> <meta> <meter> <nav> <noframes> <noscript> <object> <ol> <optgroup> <option> <output> <p> <param> <picture> <pre> <progress> <q> <rp> <rt> <ruby> <s> <samp> <script> <section> <select> <small> <source> <span> <strike> <strong> <style> <sub> <summary> <sup> <svg> <table> <tbody> <td> <template> <textarea> <tfoot> <th> <thead> <time> <title> <tr> <track> <tt> <u> <ul> <var> <video> <wbr>

HTML <canvas> height 属性


实例

高度和宽度为 200 像素的画布:

<canvas id="myCanvas" width="200" height="200" style="border:1px solid">
亲自试一试 »

下面有更多实例。


定义和用法

height 属性规定 canvas 元素的高度, 以像素为单位。

提示: 使用 width 属性规定 canvas 元素的宽度, 以像素为单位。

提示: 每当画布的高度或宽度被重设时,画布内容就会被清空(请看页面底部的例子)。

提示: 请在我们的 HTML Canvas 教程中学习更多有关<canvas> 的知识。


浏览器支持

表中的数字表示支持该属性的第一个浏览器版本。

属性          
height 4.0 9.0 2.0 3.1 9.0

语法

<canvas height="pixels">

属性值

描述
pixels 规定以像素计的 canvas 高度(比如 "100px" 或仅仅是 "100")。默认是 "150"。

更多实例

实例

如何通过重设 width 或 height 属性来清空画布(使用 JavaScript):

<canvas id="myCanvas" width="200" height="200" style="border:1px solid"></canvas>

<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "#92B901";
ctx.fillRect(50, 50, 100, 100);

function clearCanvas() {
    c.height = 300;
}
</script>
亲自试一试 »

Copyright ©2020-2026 freew3c.com All Rights Reserved 提供的内容仅用于学习和测试,不保证内容的正确性。