Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 背景大小为innerhtml大小_Javascript_Html_Css_Browser_Resize - Fatal编程技术网

Javascript 背景大小为innerhtml大小

Javascript 背景大小为innerhtml大小,javascript,html,css,browser,resize,Javascript,Html,Css,Browser,Resize,从这个脚本中,我从浏览器窗口获得了宽度和高度。我想将我的html背景图像设置为100%的大小。(无论屏幕大小如何)。其他元素(导航栏、文本、图片或svg)必须根据大小进行调整 -->我不想要滚动条,任何时候:) window.onload=函数() { //布列特和布劳瑟芬斯特酒店 var iWidth=window.innerWidth | |(window.document.documentElement.clientWidth | | window.document.body.client

从这个脚本中,我从浏览器窗口获得了宽度和高度。我想将我的html背景图像设置为100%的大小。(无论屏幕大小如何)。其他元素(导航栏、文本、图片或svg)必须根据大小进行调整

-->我不想要滚动条,任何时候:)

window.onload=函数()
{
//布列特和布劳瑟芬斯特酒店
var iWidth=window.innerWidth | |(window.document.documentElement.clientWidth | | window.document.body.clientWidth);
var iHeight=window.innerHeight | | |(window.document.documentElement.clientHeight | | window.document.body.clientHeight);
var bWin=document.getElementById('bWin');
bWin.innerHTML=“Fensterbreite”+iWidth+“
Fensterhöhe”+iHeight; window.onresize=函数(evt) { var width=window.innerWidth | | |(window.document.documentElement.clientWitdh | | window.document.body.clientWidth); var height=window.innerHeight | | |(window.document.documentElement.clientHeight | | window.document.body.clientHeight); var bWin=document.getElementById('bWin'); bWin.innerHTML=“Aktuelle Breite”+宽度+“
Aktuelle Höhe”+高度; } }
不能100%确定您的要求,但我认为您正在尝试拉伸背景图像以匹配浏览器的宽度/高度。。。。。你要走的路看起来特别复杂,为什么不试试简单的CSS呢

body,html { width: 100%; height 100%; }

body {
        background: url(images/bg.jpg) no-repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
        /*ie8 Fix*/
         filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='.myBackground.jpg', sizingMethod='scale');
-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='myBackground.jpg', sizingMethod='scale')";
zoom:1;

}
这是横穿者的作品

要调整页面元素(div、nav等)的大小,您需要查看css媒体查询响应性设计(使用%表示宽度+高度),如果您是响应性网站的新手,您可能应该在谷歌上搜索一些资料来了解这一点

这是一个快速的例子,说明了在媒体查询中响应式设计css可能是什么样子

#container { 
 width: 900px;
 margin: 0 auto;
}
@media (max-width: 900px) {
 #container { 
  width: 100%;
 }
}
#container { 
 width: 900px;
 margin: 0 auto;
}
@media (max-width: 900px) {
 #container { 
  width: 100%;
 }
}