- 微信扫码关注公众号 :前端前端大前端,追求更精致的阅读体验 ,一起来学习啊
- 关注后发送关键资料,免费获取一整套前端系统学习资料和老男孩python系列课程
api
code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>canvas</title>
</head>
<body>
<canvas id="canvas" width="400" height="400"></canvas>
<script>
var canvas = document.getElementById("canvas");
canvas.style.background = "#000";
var context = canvas.getContext("2d");
var createLinearGradient = context.createLinearGradient(100, 100, 100, 200);
createLinearGradient.addColorStop(0, 'skyblue');
createLinearGradient.addColorStop(1, 'white');
context.fillStyle = createLinearGradient;
context.fillRect(100, 100, 200, 200);
</script>
</body>
</html>
效果图
补充