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()

 







目录
相关文章
|
11月前
|
JavaScript 前端开发 开发者
Vue 动态添加 HTML 元素组件封装使用方法及长尾关键词优化指南
本文详细介绍了Vue中动态添加HTML元素的使用方法与组件封装技巧。内容涵盖条件渲染(v-if/v-show)、列表渲染(v-for)、动态组件(:is)、手动操作DOM及动态创建组件实例等核心方法。同时,通过动态表单、弹窗组件和动态加载组件的封装示例,展示如何提升代码复用性和可维护性。最后,总结性能优化策略与注意事项,如批量更新DOM、懒加载大型组件及避免直接操作DOM等,帮助开发者在实际项目中灵活应用Vue动态元素管理功能。
325 15
|
7月前
|
XML 前端开发 C#
C#编程实践:解析HTML文档并执行元素匹配
通过上述步骤,可以在C#中有效地解析HTML文档并执行元素匹配。HtmlAgilityPack提供了一个强大而灵活的工具集,可以处理各种HTML解析任务。
342 19
|
10月前
|
移动开发 前端开发 JavaScript
HTML表单验证:确认input元素输入为具有特定整数和小数位数的数值。
将上述JavaScript代码与HTML一同使用,便可以确保用户输入的数值符合特定的格式要求。特别要注意,在实际的生产环境中,仅仅依靠前端验证是不够的。为了安全起见,后端也应该实施相应的验证措施,以防止不匹配格式的数据通过其他手段提交到服务器。
562 74
|
11月前
|
JavaScript 前端开发 开发者
Vue 动态添加 HTML 元素组件封装使用方法及长尾关键词优化指南
本文详细介绍了Vue中动态添加HTML元素的多种方法与组件封装技巧,涵盖条件渲染(v-if/v-show)、列表渲染(v-for)、动态组件(:is)、手动DOM操作及动态创建组件实例等内容。同时提供了性能优化建议,如批量更新DOM、使用v-show代替v-if以及懒加载大型组件等。通过合理封装组件,可提高代码复用性和维护性。文中还附有具体示例代码,帮助开发者更好地理解和应用相关技术。适用于前端开发人员学习和实践Vue动态元素处理与组件设计。
268 19
|
11月前
|
缓存 JavaScript 前端开发
Vue 项目中动态添加 HTML 元素的方法与实践
本文探讨了 Vue 中动态添加 HTML 元素的多种技术方案,包括条件渲染(v-if/v-show)、动态组件(component :is)、手动挂载($mount)及 Vuex 状态管理等方法。通过实例分析,如动态表单生成器与全局模态框服务,展示了这些方案在实际开发中的应用。同时提供了性能优化建议和注意事项,帮助开发者根据需求选择最佳方式,在保持 Vue 响应式特性的同时实现灵活交互。附带代码示例,便于理解和实践。
400 2
|
移动开发 前端开发 HTML5
基于HTML5+Canvas绘制的鼠标跟随三角形碎片光标动画代码
基于HTML5+Canvas绘制的鼠标跟随三角形碎片光标动画特效代码,很有意思,一团三角形碎片跟随鼠标的移动,不冗长、不笨重,反而有一种很轻盈的感觉,非常不错
240 29
|
移动开发 前端开发 HTML5
Html5 Canvas绘制圆形仪表盘动画源码
Html5 Canvas绘制圆形仪表盘动画特效是一款基于HTML5 Canvas绘制的圆形百分比仪表盘动画特效。
214 1
|
Web App开发 移动开发 前端开发
html5 canvas五彩碎纸屑飘落动画特效
h5 canvas飘落纸片动画是一款实现五彩纸屑飘落的背景动画特效,基于canvas绘制的空中飘落的纸屑片动画特效,适用于网页动态背景效果代码。简单使用,欢迎下载!代码适用浏览器:搜狗、360、FireFox(建议)、Chrome、Safari、Opera、傲游、世界之窗,是一款不错的的特效插件,希望大家喜欢!
263 5
|
存储 移动开发 数据处理
HTML5 元素2
HTML5引入了多个新元素以增强表单功能和用户体验。`&lt;keygen&gt;`元素用于生成密钥对,提交表单时生成私钥和公钥,私钥保存在客户端,公钥发送至服务器,用于后续的身份验证。`&lt;output&gt;`元素则用于展示计算结果或其他脚本输出,如表单数据处理的结果。此外,`&lt;datalist&gt;`元素可与`&lt;input&gt;`元素结合使用,提供预定义的选项列表,增强输入的便捷性和准确性。这些元素共同提升了网页的交互性和安全性。