38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
<!DOCTYPE html>
|
|
<html lang="ja">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>グラデーション背景</title>
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
overflow: hidden;
|
|
}
|
|
canvas {
|
|
display: block;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<canvas id="gradientCanvas"></canvas>
|
|
<script>
|
|
// キャンバスの設定
|
|
const canvas = document.getElementById('gradientCanvas');
|
|
const ctx = canvas.getContext('2d');
|
|
|
|
// キャンバスサイズを設定
|
|
canvas.width = 1280;
|
|
canvas.height = 720;
|
|
|
|
// グラデーションの作成
|
|
const gradient = ctx.createLinearGradient(0, 0, 0, canvas.height);
|
|
gradient.addColorStop(0, 'purple'); // 上部の色
|
|
gradient.addColorStop(1, 'pink'); // 下部の色
|
|
|
|
// グラデーションを適用
|
|
ctx.fillStyle = gradient;
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
</script>
|
|
</body>
|
|
</html>
|