html5中的线性渐变与径向渐变

线性渐变代码

function show(){
    var obj=document.getElementById("demo");
    var context=obj.getContext("2d");
    var g=context.createLinearGradient(0,0,0,300);
    
    //都有一个渐变的过程滴呀;
    //就是这一样滴呀;
    //这个是我们的线程渐变;
    //线性渐变的颜色添加滴呀;
    
    g.addColorStop(0,'red');
    g.addColorStop(0.5,'white');
    g.addColorStop(1,'red');
    //尼玛,渐变,至少也是两种颜色之间额渐变id呀;u7a;
    //我操尼玛i一;
    //这个就是线性的渐变id呀;
    //g.addColorStop(0.5,'rgb(0,255,0)');
    //g.addColorStop(1,'rgb(0,0,255)');
    
    context.fillStyle=g;
    context.fillRect(0,0,400,300);
   }

效果:

径向渐变代码:

function show(){
    var obj=document.getElementById("demo");
    var context=obj.getContext("2d");
    context.beginPath();
    var grad=context.createRadialGradient(70,70,20,70,70,70);
    //同心圆滴呀;70,70,20 开始的小圆,然后向外“渐变”
    //到70,70,70 ”终点圆“ 为止滴呀;
    grad.addColorStop(0,'red');
    grad.addColorStop(0.5,'white');
    grad.addColorStop(1,'red');
    
    context.fillStyle=grad;
    context.arc(70,70,70,0,Math.PI*2);
    context.fill();
   }

效果:

 

如果我们把它换成正方形,又会咋样呢?

代码:context.rect(0,0,140,140);

效果:

其实很简单,就是tmd的一个渐变嘛!

转载于:https://www.cnblogs.com/mc67/p/5157937.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值