Canvas createLinearGradient API

createLinearGradient

addColorStop

DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>createLinearGradienttitle>
head>

<body>
    <canvas id='myCanvas' width='800' height='600'>
        your browser does not support canvas
    canvas>
    <script type="text/javascript">
    var c = document.getElementById('myCanvas');
    var ctx = c.getContext('2d');
    var grd = ctx.createLinearGradient(0, 0, 200, 0);
    grd.addColorStop(0.2, '#00ff00');
    grd.addColorStop(0.8, '#ff0000');
    ctx.fillStyle = grd;
    ctx.fillRect(0, 0, 200, 100);
    script>
body>

html>

 

转载于:https://www.cnblogs.com/stono/p/4670876.html

你可能感兴趣的:(Canvas createLinearGradient API)