简体   繁体   中英

Resizing a div and background with javascript

I'm trying to change the height of my header div and its background based on the height of the screen.

Here is what I have so far:

function getScreenSize() {
"use strict";
var h = window.innerHeight;

document.getElementById("header").style.height = h;
}

and then I used onload with the body tag.

<body onload="getScreenSize()">

Here's the full site on js fiddle just in case.

thanks for your help.

使用JavaScript设置样式时,需要指定单位:

document.getElementById("header").style.height = h + 'px';  //added + 'px'

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