HTML5技术

HTML5 canvas学习小例代码 - 风雨后见彩虹

字号+ 作者:H5之家 来源:H5之家 2017-07-01 08:01 我要评论( )

1.HTML5中的Canvas标签的创建 window.onload = function (){ createCanvas(); } function createCanvas(){ var canvas_width= 200, canvas_height = 200 ;document.body.innerHTML = "canvas id=\"canvas\" width=\""+canvas_width+"\" height=\""+canvas_he

1.HTML5中的Canvas标签的创建

window.onload = function(){ createCanvas(); } function createCanvas(){ var canvas_width= 200, canvas_height = 200; document.body.innerHTML = "<canvas id=\"canvas\" width=\""+canvas_width+"\" height=\""+canvas_height+"\"></canvas>"; }

2.HTML5Canvas标签绘制图形

var canvas_width= 500, canvas_height = 500; var mycanvas, context; window.onload = function(){ createCanvas(); drawRect(); } function createCanvas(){ document.body.innerHTML = "<canvas id=\"mycanvas\" width=\""+canvas_width+"\" height=\""+canvas_height+"\"></canvas>"; mycanvas = document.getElementById("mycanvas"); context = mycanvas.getContext("2d"); } function drawRect(){ context.fillStyle ="#FF0000"; context.fillRect(0,0,200,200); }

3.HTML5Canvas标签绘制图片

var canvas_width= 500, canvas_height = 500; var mycanvas, context; window.onload = function(){ createCanvas(); drawImage(); } function createCanvas(){ document.body.innerHTML = "<canvas id=\"mycanvas\" width=\""+canvas_width+"\" height=\""+canvas_height+"\"></canvas>"; mycanvas = document.getElementById("mycanvas"); context = mycanvas.getContext("2d"); } function drawImage(){ var img = new Image(); img.onload = function(){ context.drawImage(img,0,0); } img.src = "1.png"; }

 

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • canvas合成海报所遇问题及解决方案总结 - 静心慢跑

    canvas合成海报所遇问题及解决方案总结 - 静心慢跑

    2017-06-29 17:00

  • ios加载html5 audio标签用js无法自动播放 - MissCarrie

    ios加载html5 audio标签用js无法自动播放 - MissCarrie

    2017-06-29 09:04

  • Angular2入门学习 - Anlycp

    Angular2入门学习 - Anlycp

    2017-06-27 13:05

  • HTML5 之图片上传预处理 - 狙击手+

    HTML5 之图片上传预处理 - 狙击手+

    2017-06-26 10:01

网友点评
o