Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.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 怎样才能找到“一个”呢;“最大化”;浏览器窗口的高度?_Javascript_Jquery_Html_Css - Fatal编程技术网

Javascript 怎样才能找到“一个”呢;“最大化”;浏览器窗口的高度?

Javascript 怎样才能找到“一个”呢;“最大化”;浏览器窗口的高度?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我试图让一张图片占据用户屏幕的70%。但是,如果页面加载时屏幕变小,或者用户打开了inspect元素,则图片会变小并拉伸。我认为最好的解决方案是找到浏览器窗口的最大高度,并使图像达到该大小。然而,我不知道如何做到这一点 以下是我当前用于调整图像大小的代码: var topoffset = window.innerHeight * 0.77; var profilestart = topoffset - $(".prof-header").height(); $('.splashPic').css

我试图让一张图片占据用户屏幕的70%。但是,如果页面加载时屏幕变小,或者用户打开了inspect元素,则图片会变小并拉伸。我认为最好的解决方案是找到浏览器窗口的最大高度,并使图像达到该大小。然而,我不知道如何做到这一点

以下是我当前用于调整图像大小的代码:

var topoffset = window.innerHeight * 0.77;
var profilestart = topoffset - $(".prof-header").height();
$('.splashPic').css("height", topoffset);
$('.splashPlaceholder').css("top", profilestart);
我还想让它,如果有人使用一个巨大的显示器(即大型Mac),图像大小最大的一点?任何建议都会很有帮助


编辑:我不想动态调整图像大小。只加载一次。

听起来您想做的事情是这样的:

img{
    display:block;
    width:70%;
    min-width:320px;
    max-width:1200px;
}
img
{
    height: 70vh;
}

使用
window.screen.availHeight
而不是
window.innerHeight

var x = screen.height*0.7;
屏幕高度

var x = screen.height*0.7;
编辑:这里有更多的代码来说明它可以满足您的要求。获取加载时的高度,不调整大小

<img id="img2" src="http://lorempixel.com/320/240/food" />

<script>
$(document).ready(function () {
    var x = screen.height*0.7;
    $('#img2').css("height",x);
}
</script>  

$(文档).ready(函数(){
var x=屏幕高度*0.7;
$('#img2').css(“高度”,x);
}

如果您希望图像占据视口高度的70%(并明显保留其比率),您可以使用新的css单元
vh
(视口高度),如下所示:

img{
    display:block;
    width:70%;
    min-width:320px;
    max-width:1200px;
}
img
{
    height: 70vh;
}

我想确定的是高度,而不是宽度。如果您使用了这个或它帮助您将答案标记为已接受,请。如果您没有使用这个,您能展示一下您所做的吗?