标签:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <canvas id="canvas" style="margin:0 auto;border:1px #ddd solid;"> The current browser does not support Canvas, can replace the browser a try! </canvas> <script> window.onload = function(){ var canvas = document.getElementById(‘canvas‘); canvas.width = 800; canvas.height = 800; if(canvas.getContext(‘2d‘)){ var context = canvas.getContext(‘2d‘); // begin var linearGrad = context.createLinearGradient(0,0,200,800); linearGrad.addColorStop(0.0,‘white‘); linearGrad.addColorStop(0.25,‘yellow‘); linearGrad.addColorStop(0.5,‘green‘); linearGrad.addColorStop(0.75,‘blue‘); linearGrad.addColorStop(1.0,‘black‘); context.fillStyle = linearGrad; context.fillRect(0,0,800,800) }else{ alert(‘当前游览器不支持Canvas,请更换游览器后再试!‘); } } </script> </body> <script> /*总结 step 1 //修改xstart,ystart,xend,yend 改变渐变方向 //修改fillRect 改变渐变区域 var grd = context.creatLinearGradient(xstart,ystart,xend,yend) step 2 //stop的值域[0,1] grd.addColorStop(stop,color) */ </script> </html>
标签:
原文地址:http://www.cnblogs.com/cynthia-wuqian/p/4981636.html