HTML5 界面元素 Canvas 参考手册

简介: HTML5 界面元素 Canvas 参考手册太阳火神的美丽人生 (http://blog.csdn.net/opengl_es)本文遵循“署名-非商业用途-保持一致”创作公用协议转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino,否则,出自本博客的文章拒绝转载或再转载,谢谢合作。

HTML5 界面元素 Canvas 参考手册

太阳火神的美丽人生 (http://blog.csdn.net/opengl_es)

本文遵循“署名-非商业用途-保持一致”创作公用协议

转载请保留此句:太阳火神的美丽人生 -  本博客专注于 敏捷开发及移动和物联设备研究:iOS、Android、Html5、Arduino、pcDuino否则,出自本博客的文章拒绝转载或再转载,谢谢合作。



HTML5 界面元素 Canvas 参考手册
HTML Canvas Reference



描述
Description


The HTML5 <canvas> tag is used to draw graphics, on the fly, via scripting (usually JavaScript).

However, the <canvas> element has no drawing abilities of its own (it is only a container for graphics) - you must use a script to actually draw the graphics.

The getContext() method returns an object that provides methods and properties for drawing on the canvas.

This reference will cover the properties and methods of the getContext("2d") object, which can be used to draw text, lines, boxes, circles, and more - on the canvas.



浏览器支持
Browser Support


Internet Explorer 9, Firefox, Opera, Chrome, and Safari support <canvas> and its properties and methods.

Note: Internet Explorer 8 and earlier versions, do not support the <canvas> element.



颜色、样式和阴影
Colors, Styles, and Shadows


Property

Description

fillStyle

Sets or returns the color, gradient, or pattern used to fill the drawing

strokeStyle

Sets or returns the color, gradient, or pattern used for strokes

shadowColor

Sets or returns the color to use for shadows

shadowBlur

Sets or returns the blur level for shadows

shadowOffsetX

Sets or returns the horizontal distance of the shadow from the shape

shadowOffsetY

Sets or returns the vertical distance of the shadow from the shape


Method

Description

createLinearGradient()

Creates a linear gradient (to use on canvas content)

createPattern()

Repeats a specified element in the specified direction

createRadialGradient()

Creates a radial/circular gradient (to use on canvas content)

addColorStop()

Specifies the colors and stop positions in a gradient object




线条样式
Line Styles


Property

Description

lineCap

Sets or returns the style of the end caps for a line

lineJoin

Sets or returns the type of corner created, when two lines meet

lineWidth

Sets or returns the current line width

miterLimit

Sets or returns the maximum miter length



矩形
Rectangles


Method

Description

rect()

Creates a rectangle

fillRect()

Draws a "filled" rectangle

strokeRect()

Draws a rectangle (no fill)

clearRect()

Clears the specified pixels within a given rectangle


路径
Paths

Method

Description

fill()

Fills the current drawing (path)

stroke()

Actually draws the path you have defined

beginPath()

Begins a path, or resets the current path

moveTo()

Moves the path to the specified point in the canvas, without creating a line

closePath()

Creates a path from the current point back to the starting point

lineTo()

Adds a new point and creates a line from that point to the last specified point in the canvas

clip()

Clips a region of any shape and size from the original canvas

quadraticCurveTo()

Creates a quadratic Bézier curve

bezierCurveTo()

Creates a cubic Bézier curve

arc()

Creates an arc/curve (used to create circles, or parts of circles)

arcTo()

Creates an arc/curve between two tangents

isPointInPath()

Returns true if the specified point is in the current path, otherwise false




转换
Transformations


Method

Description

scale()

Scales the current drawing bigger or smaller

rotate()

Rotates the current drawing

translate()

Remaps the (0,0) position on the canvas

transform()

Replaces the current transformation matrix for the drawing

setTransform()

Resets the current transform to the identity matrix. Then runs transform()




文本
Text


Property

Description

font

Sets or returns the current font properties for text content

textAlign

Sets or returns the current alignment for text content

textBaseline

Sets or returns the current text baseline used when drawing text


Method

Description

fillText()

Draws "filled" text on the canvas

strokeText()

Draws text on the canvas (no fill)

measureText()

Returns an object that contains the width of the specified text




图像绘制
Image Drawing


Method

Description

drawImage()

Draws an image, canvas, or video onto the canvas




像素操作
Pixel Manipulation

Property

Description

width

Returns the width of an ImageData object

height

Returns the height of an ImageData object

data

Returns an object that contains image data of a specified ImageData object


Method

Description

createImageData()

Creates a new, blank ImageData object

getImageData()

Returns an ImageData object that copies the pixel data for the specified rectangle on a canvas

putImageData()

Puts the image data (from a specified ImageData object) back onto the canvas




混合
Compositing


Property

Description

globalAlpha

Sets or returns the current alpha or transparency value of the drawing

globalCompositeOperation

Sets or returns how a new image are drawn onto an existing image




其它
Other


Method

Description

save()

Saves the state of the current context

restore()

Returns previously saved path state and attributes

createEvent()

 

getContext()

 

toDataURL()

 







目录
相关文章
WK
|
2月前
|
存储 移动开发 前端开发
HTML5新增了哪些其他元素和属性
这段文字介绍了HTML5中新增的多种元素和属性,包括页面布局元素如header、nav等,表单元素如email、tel输入框等,以及其他元素如canvas、svg等。此外,还介绍了全局及表单属性,例如contenteditable、placeholder等,这些新功能显著增强了HTML5在现代网页设计与开发中的实用性与灵活性。
WK
65 1
|
10天前
|
Web App开发 移动开发 前端开发
html5 canvas五彩碎纸屑飘落动画特效
h5 canvas飘落纸片动画是一款实现五彩纸屑飘落的背景动画特效,基于canvas绘制的空中飘落的纸屑片动画特效,适用于网页动态背景效果代码。简单使用,欢迎下载!代码适用浏览器:搜狗、360、FireFox(建议)、Chrome、Safari、Opera、傲游、世界之窗,是一款不错的的特效插件,希望大家喜欢!
28 5
|
19天前
|
存储 移动开发 数据处理
HTML5 元素2
HTML5引入了多个新元素以增强表单功能和用户体验。`&lt;keygen&gt;`元素用于生成密钥对,提交表单时生成私钥和公钥,私钥保存在客户端,公钥发送至服务器,用于后续的身份验证。`&lt;output&gt;`元素则用于展示计算结果或其他脚本输出,如表单数据处理的结果。此外,`&lt;datalist&gt;`元素可与`&lt;input&gt;`元素结合使用,提供预定义的选项列表,增强输入的便捷性和准确性。这些元素共同提升了网页的交互性和安全性。
|
16天前
|
移动开发 前端开发 JavaScript
HTML5 <nav> 元素2
HTML5中的`&lt;nav&gt;`标签用于定义页面的导航链接部分,但并非所有链接都需置于其中。`&lt;aside&gt;`标签定义页面主内容外的相关信息,如侧边栏。`&lt;header&gt;`标签描述文档或节的头部区域,可用于定义内容的介绍展示区。示例包括导航、家庭旅行记录和IE9发布信息等。
|
19天前
|
移动开发 UED HTML5
HTML5 表单元素1
HTML5引入了新的表单元素,如`&lt;datalist&gt;`、`&lt;keygen&gt;`和`&lt;output&gt;`,以增强表单的功能性和用户体验。
|
21天前
|
前端开发
基于canvas实现的彩色纸屑组成文字3d动画HTML源码
基于canvas实现的彩色纸屑组成文字3d动画HTML源码
18 0
基于canvas实现的彩色纸屑组成文字3d动画HTML源码
|
21天前
|
移动开发 前端开发 HTML5
HTML5 Canvas制作的粒子十秒倒计时源码
一段基于HTML5 Canvas制作的粒子爆炸,十秒数字倒计时,全屏倒计时动画效果,给人一种非常大气的视觉感
21 0
HTML5 Canvas制作的粒子十秒倒计时源码
|
16天前
|
Web App开发 移动开发 iOS开发
HTML5 语义元素1
HTML5引入了语义元素,如`&lt;nav&gt;`、`&lt;header&gt;`、`&lt;footer&gt;`等,这些元素能清晰地向浏览器和开发者传达其内容的意义,如导航链接、头部和尾部。与非语义元素(如`&lt;div&gt;`)不同,语义元素使网页结构更加明确,有助于提升可读性和可访问性。例如,`&lt;section&gt;`标签用于定义文档中的节,而`&lt;article&gt;`标签则用于定义独立的内容,如论坛帖子、博客文章等。这些新元素在IE9及更高版本、Firefox、Chrome、Safari和Opera中得到支持。
|
1月前
|
前端开发 JavaScript
Canvas三维变化背景动画HTML源码
Canvas三维变化背景动画HTML源码
28 5
HTML 属性参考手册
HTML属性参考手册提供了常用的HTML属性列表,包括`class`、`id`、`style`、`title`等,用于定义元素的样式、唯一标识、额外信息等。此外,还包括`href`、`src`、`alt`、`name`、`value`、`target`、`type`和`placeholder`等,分别用于链接、资源路径、替代文本、表单元素名称和值、链接打开方式、表单元素类型及占位符文本的定义。