婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識(shí)庫 > HTML5 Canvas概述

HTML5 Canvas概述

熱門標(biāo)簽:高德地圖標(biāo)注錯(cuò)誤怎么修改 洛陽市伊川縣地圖標(biāo)注中心官網(wǎng) 搜狗星級(jí)酒店地圖標(biāo)注 平頂山電子地圖標(biāo)注怎么修改 會(huì)聲會(huì)影怎樣做地圖標(biāo)注效果 標(biāo)準(zhǔn)智能外呼系統(tǒng) 電銷機(jī)器人視頻 江蘇高頻外呼系統(tǒng)線路 地圖標(biāo)注自己去過的地方

<canvas>是一個(gè)新的HTML元素,這個(gè)元素可以被Script語言(通常是JavaScript)用來繪制圖形。例如可以用它來畫圖、合成圖象、或做簡(jiǎn)單的(和不那么簡(jiǎn)單的)動(dòng)畫。右面的圖象展示了一些<canvas>的應(yīng)用示例,我們將會(huì)在此教程中看到他們的實(shí)現(xiàn)。

<canvas>最先在蘋果公司(Apple)的Mac OS X Dashboard上被引入,而后被應(yīng)用于Safari。基于Gecko1.8的瀏覽器,例如Firefox 1.5,也支持這個(gè)新元素。元素<canvas>是WhatWG Web applications 1.0也就是大家都知道的HTML 5標(biāo)準(zhǔn)規(guī)范的一部分。

在本教程中,我將試著講述如何在你自己的網(wǎng)頁中使用<canvas>元素。提供的示例應(yīng)該會(huì)給你些清晰概念,即用<canvas>能做些什么的。這些示例也可作為你應(yīng)用<canvas>的起點(diǎn)。

開始使用之前
用元素<canvas>并不難,只要你具有HTML和 JavaScript的基礎(chǔ)知識(shí)。

如上所述,并不是所有現(xiàn)代瀏覽器都支持<canvas>元素,所以你需要 Firefox 1.5或更新版本、或者其他基于Gecko的瀏覽器例如Opera 9、或者最近版本的Safari才能看到所有示例的動(dòng)作。

<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>,唯一不同就是它不含 srcalt 屬性。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.它只有兩個(gè)屬性,widthheight,兩個(gè)都是可選的,并且都可以 DOM 或者 CSS 來設(shè)置。 When no width and height attributes are specified, the canvas will initially be 300 pixels wide and 150 pixels high.如果不指定width 和 height,默認(rèn)的是寬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 來調(diào)整canvas的大小,但渲染圖像會(huì)縮放來適應(yīng)布局的(如果你發(fā)現(xiàn)渲染結(jié)果看上去變形了,不必一味依賴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>專享的,就像標(biāo)準(zhǔn)的HTLM標(biāo)簽一樣,任何一個(gè)HTML元素都可以指定其 id 值。一般,為元素指定 id 是個(gè)不錯(cuò)的主意,這樣使得在腳本中應(yīng)用更加方便。

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>元素可以像普通圖片一樣指定其樣式(邊距,邊框,背景等等)。然而這些樣式并不會(huì)對(duì)canvas實(shí)際生成的圖像產(chǎn)生什么影響。下面我們會(huì)看到如何應(yīng)用樣式。如果不指定樣式,canvas默認(rèn)是全透明的。

替用內(nèi)容

Because the <canvas> element is still relatively new and isn't implemented in some browsers (such as Firefox 1.0 and Internet Explorer), we need a means of providing fallback content when a browser doesn't support the element.

因?yàn)?<canvas> 相對(duì)較新,有些瀏覽器并沒實(shí)現(xiàn),如Firefox 1.0 和 Internet Explorer,所以我們需要為那些不支持canvas的瀏覽器提供替用顯示內(nèi)容。

Luckily this is very straightforward: we just provide alternative content inside the canvas element. Browsers who don't support it will ignore the element completely and render the fallback content, others will just render the canvas normally.
For instance we could provide a text description of the canvas content or provide a static image of the dynamically rendered content. This can look something like this:

我們只需要直接在canvas元素內(nèi)插入替用內(nèi)容即可。不支持canvas的瀏覽器會(huì)忽略canvas元素而直接渲染替用內(nèi)容,而支持的瀏覽器則會(huì)正常地渲染canvas。例如,我們可以把一些文字或圖片填入canvas內(nèi),作為替用內(nèi)容:

<canvas id="stockGraph" width="150" height="150">
  current stock price: $3.15 +0.15
</canvas>

<canvas id="clock" width="150" height="150">
  <img src="images/clock.png" width="150" height="150"/>
</canvas>

結(jié)束標(biāo)簽 </canvas> 是必須的

In the Apple Safari implementation, <canvas> is an element implemented in much the same way <img> is; it does not have an end tag. However, for <canvas> to have widespread use on the web, some facility for fallback content must be provided. Therefore, Mozilla's implementation requires an end tag (</canvas>).

在Apple Safari里,<canvas>的實(shí)現(xiàn)跟<img>很相似,它并不沒有結(jié)束標(biāo)簽。然而,為了使 <canvas> 能在web的世界里廣泛適用,需要給替用內(nèi)容提供一個(gè)容身之所,因此,在Mozilla的實(shí)現(xiàn)里結(jié)束標(biāo)簽(</canvas>)是必須的。

If fallback content is not needed, a simple <canvas id="foo" ...></canvas> will be fully compatible with both Safari and Mozilla -- Safari will simply ignore the end tag.

如果沒有替用內(nèi)容,<canvas id="foo" ...></canvas> 對(duì) Safari 和 Mozilla 是完全兼容的—— Safari 會(huì)簡(jiǎn)單地忽略結(jié)束標(biāo)簽。

If fallback content is desired, some CSS tricks must be employed to mask the fallback content from Safari (which should render just the canvas), and also to mask the CSS tricks themselves from IE (which should render the fallback content).

如果有替用內(nèi)容,那么可以用一些 CSS 技巧來為并且僅為 Safari 隱藏替用內(nèi)容,因?yàn)槟切┨嬗脙?nèi)容是需要在 IE 里顯示但不需要在 Safari 里顯示。

渲染上下文(Rendering Context)

<canvas> creates a fixed size drawing surface that exposes one or more rendering contexts, which are used to create and manipulate the content shown. We'll focus on the 2D rendering context, which is the only currently defined rendering context. In the future, other contexts may provide different types of rendering; for example, it is likely that a 3D context based on OpenGL ES will be added.

<canvas> 創(chuàng)建的固定尺寸的繪圖畫面開放了一個(gè)或多個(gè)渲染上下文(rendering context),我們可以通過它們來控制要顯示的內(nèi)容。我們專注于2D 渲染上,這也是目前唯一的選擇,可能在將來會(huì)添加基于OpenGL ES 的 3D 上下文。

The <canvas> is initially blank, and to display something a script first needs to access the rendering context and draw on it. The canvas element has a DOM method called getContext, used to obtain the rendering context and its drawing functions. getContext() takes one parameter, the type of context.

<canvas> 初始化是空白的,要在上面用腳本畫圖首先需要其渲染上下文(rendering context),它可以通過 canvas 元素對(duì)象的 getContext 方法來獲取,同時(shí)得到的還有一些畫圖用的函數(shù)。getContext() 接受一個(gè)用于描述其類型的值作為參數(shù)。

var canvas = document.getElementById('tutorial');
var ctx = canvas.getContext('2d');

In the first line we retrieve the canvas DOM node using the getElementById method. We can then access the drawing context using the getContext method.

上面第一行通過 getElementById 方法取得 canvas 對(duì)象的 DOM 節(jié)點(diǎn)。然后通過其 getContext 方法取得其畫圖操作上下文。

檢查瀏覽器的支持

The fallback content is displayed in browsers which do not support <canvas>; scripts can also check for support when they execute. This can easily be done by testing for the getContext method. Our code snippet from above becomes something like this:

除了在那些不支持  的瀏覽器上顯示替用內(nèi)容,還可以通過腳本的方式來檢查瀏覽器是否支持 canvas 。方法很簡(jiǎn)單,判斷 getContext 是否存在即可。

var canvas = document.getElementById('tutorial');
if (canvas.getContext){
  var ctx = canvas.getContext('2d');
  // drawing code here
} else {
  // canvas-unsupported code here
}

代碼模板

Here is a minimalistic template, which we'll be using as a starting point for later examples. You can download this file to work with on your system.

我們會(huì)用下面這個(gè)最簡(jiǎn)化的代碼模板來(后續(xù)的示例需要用到)作為開始,你可以 下載文件 到本地備用。

<html>
  <head>
    <title>Canvas tutorial</title>
    <script type="text/javascript">
      function draw(){
        var canvas = document.getElementById('tutorial');
        if (canvas.getContext){
          var ctx = canvas.getContext('2d');
        }
      }
    </script>
    <style type="text/css">
      canvas { border: 1px solid black; }
    </style>
  </head>
  <body onload="draw();">
    <canvas id="tutorial" width="150" height="150"></canvas>
  </body>
</html>

If you look at the script you'll see I've made a function called draw, which will get executed once the page finishes loading (via the onload attribute on the body tag). This function could also have been called from a setTimeout, setInterval, or any other event handler function just as long the page has been loaded first.

細(xì)心的你會(huì)發(fā)現(xiàn)我準(zhǔn)備了一個(gè)名為 draw 的函數(shù),它會(huì)在頁面裝載完畢之后執(zhí)行一次(通過設(shè)置 body 標(biāo)簽的 onload 屬性),它當(dāng)然也可以在 setTimeout,setInterval,或者其他事件處理函數(shù)中被調(diào)用。

一個(gè)簡(jiǎn)單的例子

To start off, here's a simple example that draws two intersecting rectangles, one of which has alpha transparency. We'll explore how this works in more detail in later examples.

作為開始,來一個(gè)簡(jiǎn)單的吧——繪制兩個(gè)交錯(cuò)的矩形,其中一個(gè)是有alpha透明效果。我們會(huì)在后面的示例中詳細(xì)的讓你了解它是如何運(yùn)作的。

<html>
 <head>
  <script type="application/x-javascript">
    function draw() {
      var canvas = document.getElementById("canvas");
      if (canvas.getContext) {
        var ctx = canvas.getContext("2d");

        ctx.fillStyle = "rgb(200,0,0)";
        ctx.fillRect (10, 10, 55, 50);

        ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
        ctx.fillRect (30, 30, 55, 50);
      }
    }
  </script>
 </head>
 <body onload="draw();">
   <canvas id="canvas" width="150" height="150"></canvas>
 </body>
</html>

標(biāo)簽:果洛 廣西 常德 蚌埠 鄂爾多斯 廣東 阿克蘇 松原

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《HTML5 Canvas概述》,本文關(guān)鍵詞  HTML5,Canvas,概述,HTML5,Canvas,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《HTML5 Canvas概述》相關(guān)的同類信息!
  • 本頁收集關(guān)于HTML5 Canvas概述的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av
    午夜精品久久久久| 国产剧情一区在线| 日韩国产一二三区| 欧美三级视频在线播放| 一区二区三区视频在线看| 99久久99久久精品免费看蜜桃| 久久午夜色播影院免费高清| 国产精品一区三区| 国产视频一区二区在线观看| 国产乱码一区二区三区| 久久精品人人做人人爽97| 国产精品一卡二| 国产精品免费人成网站| 99久久婷婷国产综合精品| 国产精品久久久久aaaa| 在线精品亚洲一区二区不卡| 中文字幕佐山爱一区二区免费| 国产精品资源网| 26uuu精品一区二区在线观看| 午夜精品久久久久久久99樱桃| 色悠久久久久综合欧美99| 日韩一区在线看| 99久久精品国产精品久久| 中文字幕一区日韩精品欧美| 色琪琪一区二区三区亚洲区| 日韩极品在线观看| 国产日韩在线不卡| 欧美午夜精品一区| 国产麻豆午夜三级精品| 亚洲欧美激情视频在线观看一区二区三区| 欧美日韩精品一区二区| 性做久久久久久久免费看| 欧美精品粉嫩高潮一区二区| 亚洲午夜久久久久| 亚洲精品一线二线三线| 色一情一乱一乱一91av| 日韩电影在线一区| 国产精品久线观看视频| 欧美一区二区三区四区五区| 成人免费视频caoporn| 亚洲成人中文在线| 国产精品视频第一区| 欧美一区二区高清| 色婷婷激情综合| 国产麻豆欧美日韩一区| 三级在线观看一区二区| 亚洲视频电影在线| 欧美白人最猛性xxxxx69交| 91蜜桃免费观看视频| 韩国v欧美v日本v亚洲v| 性久久久久久久| 亚洲精品乱码久久久久久日本蜜臀| 精品国产欧美一区二区| 欧美日韩亚洲综合在线| 色婷婷av一区二区三区gif| 粉嫩欧美一区二区三区高清影视| 蜜桃av一区二区在线观看| 亚洲激情在线播放| 国产精品福利电影一区二区三区四区| 精品久久五月天| 日韩亚洲欧美综合| 欧美人xxxx| 欧美日韩国产片| 91女神在线视频| 99久久亚洲一区二区三区青草| 国产一区二区三区在线观看精品| 亚洲.国产.中文慕字在线| 中文字幕日韩一区| 久久久精品免费网站| 久久久精品2019中文字幕之3| 日韩一二在线观看| 精品对白一区国产伦| 久久这里只有精品视频网| 日韩视频在线一区二区| 欧美v国产在线一区二区三区| 日韩一级完整毛片| 337p日本欧洲亚洲大胆色噜噜| 精品对白一区国产伦| 国产日韩精品一区二区三区在线| 久久久久国产成人精品亚洲午夜| 国产日韩精品一区| 成人欧美一区二区三区视频网页| 亚洲日韩欧美一区二区在线| 一区二区三区不卡视频| 图片区日韩欧美亚洲| 久久99精品国产.久久久久| 国产精品一二三四区| 丁香激情综合国产| 日本韩国精品在线| 欧美情侣在线播放| 久久久噜噜噜久噜久久综合| 国产精品传媒视频| 亚洲成人激情综合网| 老司机午夜精品99久久| 成人夜色视频网站在线观看| 色悠久久久久综合欧美99| 欧美肥妇毛茸茸| 国产无人区一区二区三区| 一区二区三区在线播放| 久久精品国产一区二区三| 懂色一区二区三区免费观看| 欧美色国产精品| 日韩一区二区精品葵司在线| 国产无人区一区二区三区| 亚洲一区在线观看免费观看电影高清 | 亚洲一区在线播放| 日本系列欧美系列| voyeur盗摄精品| 91精品国产综合久久久久久久| 国产欧美一区二区在线| 亚洲午夜电影在线| 国产成人久久精品77777最新版本| 91在线视频官网| 精品国产99国产精品| 亚洲高清不卡在线| 国产成人免费视频网站高清观看视频| 欧美老肥妇做.爰bbww| 中文在线一区二区| 免费成人av在线| 欧美曰成人黄网| 国产亚洲精品免费| 免费观看久久久4p| 欧美视频一区二区三区四区| 亚洲素人一区二区| 成人免费观看av| 国产亚洲综合av| 美女脱光内衣内裤视频久久网站| 欧美中文字幕一二三区视频| 中文字幕日本不卡| 国产精品亚洲第一区在线暖暖韩国| 欧美日韩一区二区三区免费看| 亚洲日本护士毛茸茸| 国产精品99久久不卡二区| 欧美日韩免费不卡视频一区二区三区| 国产欧美日韩不卡免费| 国产乱子轮精品视频| 欧美变态tickling挠脚心| 亚洲综合久久av| 欧美综合一区二区三区| 自拍av一区二区三区| 风间由美一区二区三区在线观看 | 九色|91porny| 欧美精品乱码久久久久久| 亚洲综合色噜噜狠狠| 成人爽a毛片一区二区免费| 精品久久久久久综合日本欧美 | 国产一区二区中文字幕| 欧美成人性战久久| 国模一区二区三区白浆| 久久久久久久久一| 国产99久久精品| 国产精品久久精品日日| 国产在线播放一区三区四| 91精品国产欧美一区二区成人| 日韩av一区二区三区| 精品国产乱子伦一区| 韩国成人精品a∨在线观看| 国产亚洲一区二区三区在线观看| 蜜臀av性久久久久蜜臀aⅴ流畅 | 欧美精品一区二区不卡| 国产激情视频一区二区三区欧美 | 91视视频在线直接观看在线看网页在线看| 中文字幕亚洲区| 欧美午夜一区二区| 久久成人免费网站| 国产精品美女久久久久久久久久久| 91国产丝袜在线播放| 亚洲精品视频免费观看| 欧美日韩精品一区二区在线播放| 免费不卡在线视频| 国产精品伦理一区二区| 欧美午夜精品电影| 国产做a爰片久久毛片| 成人免费视频在线观看| 欧美精品久久一区二区三区| 国产馆精品极品| 亚洲综合激情小说| 久久无码av三级| 欧美网站一区二区| 国产成a人亚洲精品| 亚洲午夜av在线| 国产欧美一区二区三区网站 | 欧美裸体一区二区三区| 另类中文字幕网| 亚洲精品视频在线观看网站| 欧美一区二区三区婷婷月色| 91在线视频官网| 韩国精品久久久| 亚洲成人黄色影院| 欧美国产成人在线| 日韩写真欧美这视频| 97久久精品人人爽人人爽蜜臀 | 91福利视频网站| 久久激五月天综合精品| 亚洲激情一二三区| 国产精品久久久久久久浪潮网站| 日韩一区二区免费高清| 日本高清不卡视频| 成人午夜视频免费看| 国产一区二区三区免费观看|