English 中文(简体)
我怎么做一幅画面,以完全填满浏览器?
原标题:How do I make a canvas drawing to completely fill the browser?

这里是我目前拥有的法典。

<!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在背景和轴上重复的数值。

最后,我要在地狱中增加两三个颜色,但我只含糊地理解一下,由于我给它留下了新鲜的印象,这部法典中的内容。

最佳回答
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;
        }
    }
}
问题回答

Are you adding this canvas to the body element of the page? Also, you could try

<代码>:绝对值;最高值:0px;左侧:0px;

(a) 利用cs:

#diag-cnvs{
    position: absolute;
    top:      0px;
    left:     0px;
    right:    0px;
    bottom:   0px;
    width:    100%;
    height:   100%;
}

这样做是可能的,我用Canvas做,尽管该法典是在国内的,而I m正在工作,因此我就应该做些什么。 值得指出的是,如果你想要保持图像/扫描的正确方面比例,那么你需要使用Javales(我可以说出,向我开一点),否则,你可以使用纯的CSS:

... header (snip) ...
</head>
<body>
    <div id="Page">
        <canvas id="MyCanvas" width="500" height="500"></canvas>
    </div>
</body>
</html>

CSS:

body { width: 100%; height: 100%; }
#Page { position: absolute; top: 0; right: 0; bottom: 0; left: 0 }

#MyCanvas { height: 100%; width: 100%; }

如果做不到这一点,就会试图改变第MyCanvas号。

#MyCanvas { position: absolute; top: 0; right: 0; bottom: 0; left: 0 }

我确信,这是这方面的事情,我已经做了这项工作,在我工作回家时,我重复检查我的法典。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签