这是我目前拥有的代码。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script>
function draw()
{
var diagCanvas = document.getElementById("diag-cnvs");
diagCanvas.height=window.innerHeight;
diagCanvas.width=window.innerWidth;
if (diagCanvas.getContext)
{
var ctx = diagCanvas.getContext("2d");
var h = w = 100;
var color1 = 'rgba(255,0,0,1)';
var color2 = 'rgba(255,0,0,.2)';
var x = y = 0;
while(y<diagCanvas.height)
{
while(x<diagCanvas.width)
{
ctx.fillStyle = color2;
ctx.fillRect( x, y, w, h);
ctx.fillStyle = color1;
ctx.lineTo( x, y);
ctx.lineTo( x+w/2, y);
ctx.lineTo( x, y+h/2);
ctx.lineTo( x, y);
ctx.moveTo( x+w, y);
ctx.lineTo( x+w, y+h/2);
ctx.lineTo( x+w/2, y+h);
ctx.lineTo( x, y+h);
ctx.fill();
ctx.closePath();
x+=w;
}
y+=h;
x=0;
}
}
}
$(function() {
draw();
})
</script>
<style>
canvas {
position: absolute;
top: 0;
left: 0;
}
</style>
</head>
<body>
<canvas height="100" width="100" id="diag-cnvs"></canvas>
</body>
</html>
我想保持画布形状的高度和宽度尺寸相同,但如果能 100% 完全填充浏览器或基本上无限重复,那就太好了,类似于要重复的背景图像的 CSS 值x 轴和 y 轴。
最终,我想在条纹中添加两到三种颜色,但我只是模糊地理解这段代码中发生的事情,因为我是全新的。
function draw()
{
var diagCanvas = document.getElementById("diag-cnvs");
if(document.documentElement.offsetHeight<window.innerHeight)
diagCanvas.height = window.innerHeight;
else
diagCanvas.width = document.documentElement.offsetHeight;
diagCanvas.width=document.documentElement.offsetWidth;
if (diagCanvas.getContext)
{
var ctx = diagCanvas.getContext("2d");
var h = w = 100;
var color1 = 'rgba(255,0,0,1)';
var color2 = 'rgba(255,0,0,.2)';
var x = y = 0;
while(y<diagCanvas.height)
{
while(x<diagCanvas.width)
{
ctx.fillStyle = color2;
ctx.fillRect( x, y, w, h);
ctx.fillStyle = color1;
ctx.lineTo( x, y);
ctx.lineTo( x+w/2, y);
ctx.lineTo( x, y+h/2);
ctx.lineTo( x, y);
ctx.moveTo( x+w, y);
ctx.lineTo( x+w, y+h/2);
ctx.lineTo( x+w/2, y+h);
ctx.lineTo( x, y+h);
ctx.fill();
ctx.closePath();
x+=w;
}
y+=h;
x=0;
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)