I’ve found mixed evidence about whether it’s feasible to create a dynamic background with the HTML5 canvas element. Here’s a guy who seems to have successfully done it:
http://radikalfx.com/files/anibg/
I have successfully positioned my canvas element as a background, but it has rendered my links unclickable. Here’s the situation:
HTML:
<div id='container'>
... other header stuff ...
<canvas id='background'>
</canvas>
<!-- Can't touch this *MC Hammer Shuffle* -->
<a href='#'>test</a>
... footer stuff ...
</div>
CSS:
/* Everything's z-index is now 1 */
#container
{
position: relative;
min-height:100%;
width:100%;
z-index:1;
}
/* Make the canvas z-index 0 */
#background
{
position: absolute;
top: 0;
width:100%;
height:100%;
z-index: 0;
}
JavaScript:
// Onload Draw an ellipse
// I've got jCanvas installed (jQuery plugin) to use the drawArc() method
// This bit can be replaced with whatever test code you want.
function load()
{
init_canvas();
$("canvas").drawArc({
fillStyle: "black",
x: 100, y: 100,
radius: 50
});
}
// Make the canvas the appropriate size
function init_canvas()
{
canvas = document.getElementById("background");
canvas.width = document.width;
canvas.height = document.height;
canvasW = canvas.width;
canvasH = canvas.height;
}
Cheers!
You use
#containerin your CSS to give everything else az-indexof 1, yet you never put an element#containeron the page.Change your HTML to the following and it will work as expected:
JSFiddle: http://jsfiddle.net/ht6c8/