码迷,mamicode.com
首页 > 其他好文 > 详细

canvas之fillStyle

时间:2018-06-22 01:01:48      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:creat   pat   col   getc   .com   oob   etc   lan   near   

菜鸟canvas  

首先:

  var  cvs = document.getElementById("canvas");

  var  ctx = cvs.getContext("2d");

  ctx.fillStyle = wumon;

  那么这里的wumon是什么呢?

  ctx.fillStyle = color | grdient | pattern;

  color,十六进制、rgb、rgba、HSL、HSLA······。

  gradient,有两种:

    线性:ctx.createLinearGradient(x,y,x1,y1);其中x、y为渐变开始的坐标,x1、y1为渐变结束时坐标;

    放射:ctx.createRadialGradient(x,y,r,x1,y1,r1);其中x、y、r为渐变开始坐标及半径,x1、y1、r1为渐变结束坐标及半径;

    同时还有一个addColorStop(stop,color);用来配合渐变使用,stop为0.0-1.0之间值,color为stop颜色,addColorStop可多次调用来调节渐变。

    示例:

       var linear = ctx.createLinearGradient(x,y,x1,y1);

       linear.addColorStop(0,"red");

       linear.addColorStop(1,"blue");

       ctx.fillStyle = linear;

  pattern

    ctx.createPattern(imageEle,"repeat" | "repeat-x" | "repeat-y" | "no-repeat");

    示例:

      var img = document.getElementById("img");

      var pat = ctx.createPattern(img,"repeat");

      ctx.fillStyle = pat;

 

canvas之fillStyle

标签:creat   pat   col   getc   .com   oob   etc   lan   near   

原文地址:https://www.cnblogs.com/wumon/p/9211486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!