当前位置:Gxlcms > html代码 > canvas基础

canvas基础

时间:2021-07-01 10:21:17 帮助过:35人阅读

1.元素

替换内容

元素不同于在其中的标签,就像


  current stock price: $3.15 +0.15



  

标签不可省

2.渲染上下文(The rendering context)

WebGL 使用了基于OpenGL ES的3D上下文 ("experimental-webgl")

我们将会将注意力放在2D渲染上下文中

canvas起初是空白的。为了展示,首先脚本需要找到渲染上下文,然后在它的上面绘制。 元素有一个做 getContext() 的方法,这个方法是用来获得渲染上下文和它的绘画功能。getContext()只有一个参数,上下文的格式。对于2D图像而言,如本教程,你可以使用 CanvasRenderingContext2D。

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

3.检查支持性

var canvas = document.getElementById('tutorial');

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

4.一个模板骨架


  
    Canvas tutorial
    

5.一个简单例子


 
  

人气教程排行