【发布时间】:2011-12-11 21:25:48
【问题描述】:
我发现了关于使用 HTML5 画布元素创建动态背景是否可行的各种证据。这里有一个人似乎已经成功地做到了:
http://radikalfx.com/files/anibg/
我已成功地将我的画布元素定位为背景,但它使我的链接无法点击。情况如下:
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;
}
干杯!
【问题讨论】:
-
我收到错误 Uncaught TypeError: Object [object Object] has no method 'drawArc'。请记住,
$()返回一个 jQuery 对象(如果您使用的是 jQuery)。 -
是否有特定的方法需要将画布设置为背景?我觉得我的做法是一种变通方法,而不是正确的实施方式
-
@FelixKling 你安装了 jCanvas 吗?这是使用我给出的示例内容所必需的 api 的一部分。我将编辑帖子以反映这一点
-
啊……我猜就是这样;)
-
发布了编辑,糟糕。可以用任何可以确保 Canvas 正常工作的东西来替换该部分。只需标准的 javascript 即可。我只想和 Canvas 一起学习 jQuery
标签: javascript css html canvas