Created
May 29, 2011 15:03
-
-
Save tango238/997838 to your computer and use it in GitHub Desktop.
[HTML5] 背景をグラデーションにする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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