简体   繁体   English

如何使元素具有页面(文档)的 100% 宽度和高度,而不仅仅是窗口(浏览器)?

[英]How do I make an element 100% width and height of the page (document) and not just the window (browser)?

I've got this piece of code that has a slight twinkling animation that I'm wanting to use as a background but current it's only filling the browser window and I want it to fill the entire page/document.我有一段代码,它有一个轻微的闪烁动画,我想用作背景,但目前它只填充浏览器窗口,我希望它填充整个页面/文档。

Can anyone help?任何人都可以帮忙吗? JSFiddle here - https://jsfiddle.net/83aahcng/1/ JSFiddle在这里 - https://jsfiddle.net/83aahcng/1/

<div id="container">
  <canvas id="pixie"></canvas>
  <div class="content">
    <p>This is some content</p>
  </div>
</div>

change your setDimensions like below:更改您的setDimensions如下所示:

    function setDimensions(e) {   
 var body = document.body,
    html = document.documentElement;
            WIDTH = window.innerWidth;
            HEIGHT =  Math.max( body.scrollHeight, body.offsetHeight, 
                       html.clientHeight, html.scrollHeight, html.offsetHeight );
            container.style.width = WIDTH+'px';
            container.style.height = HEIGHT+'px';
            canvas.width = WIDTH;
            canvas.height = HEIGHT;
        }

https://jsfiddle.net/83aahcng/2/ https://jsfiddle.net/83aahcng/2/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM