暂无图片
暂无图片
暂无图片
暂无图片
暂无图片
[HTML5资料]Canvas入门基础教程.pdf
286
81页
0次
2021-02-22
50墨值下载
HTML5 资料
1
1
1
1 Canvas
Canvas
Canvas
Canvas 教程
<canvas> 是一个新的用于通过脚本(通常 JavaScript )绘图的 HTML 元素。例如,他可以用于
图、制作图片的组合或者简单的动画(当然并不那么简单) It can for instance be used to draw
graphs, make photo compositions or do simple (and not so simple) animations.
1.1
1.1
1.1
1.1 基本用法
Basic usage
<canvas> 元素
Let's start this tutorial by looking
at
the <canvas> element itself.
让我们从
<canvas>
元素的定义开始吧
<canvas id="tutorial" width="150" height="150"></canvas>
This looks a lot like the <img> element, the only difference is that it doesn't have the src and alt attributes.
<canvas> 看起来很像 <img> ,唯一不同就是它不含 src alt 属性 The <canvas> element has only two
attributes - width and height. These are both optional and can also be set using DOM properties or CSS
rules. 它只有两个属性, width height ,两个都是可选的,并且都可以 DOM 或者 CSS 来设置。
When no width and height attributes are specified, the canvas will initially be 300 pixels wide and 150
pixels high. 如果不指定 width height ,默认的是 300 像素,高 150 像素 The element can be
sized arbitrarily by CSS, but during rendering the image is scaled to fit its layout size. (If your renderings
seem distorted, try specifying your width and height attributes explicitly in the <canvas> attributes, and
not with CSS.) 虽然可以通 CSS 来调 canvas 的大小,但渲染图像会缩放来适应布局的(如果你发
现渲染结果看上去变形了,不必一味依 CSS ,可以尝试显式指 canvas width height 属性
值)
The id attribute isn't specific to the <canvas> element but is one of default HTML attributes which can be
applied to (almost) every HTML element (like class for instance). It's always a good idea to supply an id
because this makes it much easier to identify it in our script.
id 属性不是 <canvas> 专享的,就像标准 HTLM 标签一样,任何一 HTML 元素都可以指定其 id
值。一般,为元素指定 id 是个不错的主意,这样使得在脚本中应用更加方便。
The <canvas> element can be styled just like any normal image (margin, border, background, etc). These
rules however don't affect the actual drawing on the canvas. We'll see how this is done later in this
tutorial. When no styling rules are applied to the canvas it will initially be fully transparent. <canvas> 元素
可以像普通图片一样指定其样式(边距,边框,背景等等)。然而这些样式并不会对 canvas 实际
of 81
50墨值下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

关注
最新上传
暂无内容,敬请期待...
下载排行榜
Top250 周榜 月榜