简体   繁体   中英

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/

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

change your setDimensions like below:

    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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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