首页 > 其他 > 详细

颜色渐变

时间:2020-10-06 15:06:01      阅读:35      评论:0      收藏:0      [点我收藏+]

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>渐变</title>
<style>
* {
margin: 0;
padding: 0;
}

ul {
list-style: none;
}

canvas {
border: solid 1px #000;
display: block;
margin: 100px auto;
}
</style>
</head>
<body>
<canvas></canvas>
<script>
var canvas = document.querySelector(‘canvas‘);

canvas.width = 600;
canvas.height = 400;

//获取画笔
var ctx = canvas.getContext(‘2d‘);

//线性渐变
// var gradient = ctx.createLinearGradient(0,0,canvas.width,canvas.height);
var gradient = ctx.createLinearGradient(100,100,500,300);

//设置颜色
gradient.addColorStop(0, ‘red‘);
gradient.addColorStop(0.5, ‘yellow‘);
gradient.addColorStop(1, ‘blue‘);

//修改填充样式
ctx.fillStyle = gradient;
//
ctx.fillRect(0,0,canvas.width, canvas.height);

</script>
</body>
</html>

颜色渐变

原文:https://www.cnblogs.com/eric-share/p/13773229.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!