Skip to content

Instantly share code, notes, and snippets.

@tango238
Created May 29, 2011 15:03
Show Gist options
  • Save tango238/997838 to your computer and use it in GitHub Desktop.
Save tango238/997838 to your computer and use it in GitHub Desktop.
[HTML5] 背景をグラデーションにする
<!DOCTYPE HTML>
<html lang="ja">
<head>
<title>グラデーションの背景</title>
<meta charset="utf-8">
</head>
<body>
<script type="text/javascript">
// Bg gradient
var canvas = document.createElement( 'canvas' );
canvas.width = 1;
canvas.height = window.innerHeight;
var context = canvas.getContext( '2d' );
var gradient = context.createLinearGradient( 0, 0, 0, canvas.height );
gradient.addColorStop(0, "#ffffff");
gradient.addColorStop(.5, "#000000");
context.fillStyle = gradient;
context.fillRect(0, 0, canvas.width, canvas.height);
document.body.style.background = 'url(' + canvas.toDataURL('image/png') + ')';
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment