32 lines
968 B
HTML
32 lines
968 B
HTML
|
<!doctype html>
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta charset="utf-8">
|
||
|
<title>Gradient Fill 1</title>
|
||
|
<link rel="stylesheet" href="../include/style.css">
|
||
|
</head>
|
||
|
<body>
|
||
|
<header>
|
||
|
Example from <a href="http://amzn.com/1430236655?tag=html5anim-20"><em>Foundation HTML5 Animation with JavaScript</em></a>
|
||
|
</header>
|
||
|
<canvas id="canvas" width="400" height="400"></canvas>
|
||
|
|
||
|
<script>
|
||
|
window.onload = function () {
|
||
|
var canvas = document.getElementById('canvas'),
|
||
|
context = canvas.getContext('2d'),
|
||
|
pt1 = {x: 0, y: 0}, //gradient start point
|
||
|
pt2 = {x: 100, y: 100}, //gradient end point
|
||
|
gradient = context.createLinearGradient(pt1.x, pt1.y, pt2.x, pt2.y);
|
||
|
|
||
|
//white to red
|
||
|
gradient.addColorStop(0, "#ffffff");
|
||
|
gradient.addColorStop(1, "#ff0000");
|
||
|
|
||
|
context.fillStyle = gradient;
|
||
|
context.fillRect(0, 0, 100, 100);
|
||
|
};
|
||
|
</script>
|
||
|
</body>
|
||
|
</html>
|