Hello, i found this cool HTML5 feature called Gradient canvas. I would like to use it as a website background, is it possible to somehow place content on it? when i use divs and table nothing appears only this canvas.
Here is a file i want to use as a background.
Here is a file i want to use as a background.
Code:
<!DOCTYPE html>
<html lang="en"><head>
<meta charset="utf-8">
<title>ilya daderko</title>
<style>
body {
background: #000;
}
canvas {
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 100%;
background-repeat:repeat
}
body,td,th {
color: #FFF;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<canvas height="600" width="600">
</canvas>
<script>
var canvas = document.getElementsByTagName('canvas')[0],
ctx = null,
grad = null,
body = document.getElementsByTagName('body')[0],
color = 255;
if (canvas.getContext('2d')) {
ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, 600, 600);
ctx.save();
// Create radial gradient
grad = ctx.createRadialGradient(0,0,0,0,0,600);
grad.addColorStop(0, '#000');
grad.addColorStop(1, 'rgb(' + color + ', ' + color + ', ' + color + ')');
// assign gradients to fill
ctx.fillStyle = grad;
// draw 600x600 fill
ctx.fillRect(0,0,600,600);
ctx.save();
body.onmousemove = function (event) {
var width = window.innerWidth,
height = window.innerHeight,
x = event.clientX,
y = event.clientY,
rx = 600 * x / width,
ry = 600 * y / width;
var xc = ~~(256 * x / width);
var yc = ~~(256 * y / height);
grad = ctx.createRadialGradient(rx, ry, 0, rx, ry, 0.01);
grad.addColorStop(0, '#000');
grad.addColorStop(1, ['rgb(', xc, ', ', (255 - xc), ', ', yc, ')'].join(''));
// ctx.restore();
ctx.fillStyle = grad;
ctx.fillRect(0,0,600,600);
// ctx.save();
};
}
</script>
<a><img style="position: absolute; top: 0; left: 0; border: 0;" src="website/images/Logotipe2.png" alt="Fork me on GitHub"></a>
try {
var pageTracker = _gat._getTracker("UA-1656750-18");
pageTracker._trackPageview();
} catch(err) {}</script>
</body></html>
Comment