1.得到一個canvas元素 2.用canvas元素去得到一個html5內(nèi)置內(nèi)置的工具getContext("2d")
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:主機域名、網(wǎng)站空間、營銷軟件、網(wǎng)站建設(shè)、烏拉特后網(wǎng)站維護(hù)、網(wǎng)站推廣。
3.常用的方法,fillStyle屬性指明填充的顏色樣式,fillRect(x,y,width,height)畫矩形
4.畫直線moveTo(x,y) lineTo(x,y) closePath() stroke() 屬性:lineJoin 默認(rèn)是平角round是圓角 lineCap有3個值:butt(平,默認(rèn)),round(圓),square(方) lineWidth線條寬度 stokeStyle線條的顏色樣式 學(xué)習(xí)http://www.jb51.net/html5/70307.html
5畫圓形cxt2.arc(100,100,100,0,Math.PI*2,true);cxt2.closePath();cxt2.fill();
arc(x,y,r,0,Math.PI*2,true)x,y圓心 r半徑
6.漸變填充
var grd=cxt3.createLinearGradient(0,0,180,100);grd.addColorStop(0,"#FF0000");
grd.addColorStop(1,"#00FF00");cxt3.fillStyle=grd;cxt3.fillRect(0,0,180,100);
addColorStop(x,color) 0=《x《=1 開始和技術(shù)時的顏色
7.圖像填充var can4 = document.getElementById('can4');
var cxt4 = can4.getContext("2d");
var img = new Image();
img.src ="22.gif";
console.log(img);
cxt4.drawImage(img,0,0);這樣的結(jié)果并不會顯示出來圖像
因為img沒有加載進(jìn)來,解決辦法img.onload = function () {
cxt4.drawImage(img, 50, 50,100,100);
}
代碼:1.html
#can1{border:solid 1px blue;}
var can1 = document.getElementById('can1');
var cxt = can1.getContext("2d");
cxt.fillStyle="blue";
cxt.fillRect(0,0,50,50);
cxt.moveTo(60,60);
cxt.lineTo(150,60);
//cxt.moveTo(150,60);
cxt.lineTo(150,150);
cxt.lineTo(60,150);
cxt.lineTo(60,60);
//cxt.lineJoin="round";
//cxt.closePath();
cxt.lineCap="square";
cxt.lineWidth=20;
cxt.strokeStyle = 'rgba(255,0,0,0.5)';
cxt.stroke();
代碼2.html
//
var can2 = document.getElementById('can2');
var cxt2 = can2.getContext("2d");
cxt2.fillStyle="#FF0000";
cxt2.arc(100,100,100,0,Math.PI*2,true);
cxt2.closePath();
cxt2.fill();
var can3 = document.getElementById('can3');
var cxt3 = can3.getContext("2d");
var grd=cxt3.createLinearGradient(0,0,180,100);
grd.addColorStop(0,"#FF0000");
grd.addColorStop(1,"#00FF00");
cxt3.fillStyle=grd;
cxt3.fillRect(0,0,180,100);
var can4 = document.getElementById('can4');
var cxt4 = can4.getContext("2d");
var img = new Image();
img.src ="22.gif";
console.log(img);
//cxt4.drawImage(img,0,0);
img.onload = function () {
cxt4.drawImage(img, 50, 50,100,100);
}