html - 设备旋转纵向/横向视口
问题描述
iPhone 8 plus 的视口宽度有问题。下面的代码是 ipad Air 3 (2019) 的工作宽度。如果我在横向旋转 iPhone 8 plus 或 iPhone XS Max 而不是在纵向旋转,浏览器 safari 和 firefox 在纵向屏幕中增加了额外的空间。但不在横向屏幕中。但它变得更加特别:如果没有打开额外的水龙头,它只显示这种行为,而不是在每个案例中。你知道为什么它会这样吗?
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Titel</title>
<style>
* {
padding: 0;
margin:0;
}
</style>
</head>
<body style="height:100%; background-color:grey;display:grid;grid-template-rows:120px 60px calc(100% - 180px)">
<div style="background-color:green;height:100%;"></div>
<div style="background-color:red;height:100%;"></div>
<div style="background-color:blue;height:100%;"></div>
</body>
<script>
let winGroesse = window.innerHeight;
let winGroesseout;
window.onresize = reSizeFunkt;
let neueWinGroesse = winGroesse.toString() + "px";
document.querySelector('html').style.height = neueWinGroesse;
function reSizeFunkt () {
winGroesse = window.innerHeight;
neueWinGroesse = winGroesse.toString() + "px";
document.querySelector('html').style.height = neueWinGroesse;
}
</script>
</html>
解决方案
i've still not found a solution. But should someone else have that trouble i share here my ugly workaround:
let winGroesse = window.innerHeight;
let winGroesseout;
window.onresize = reSizeFunkt;
let neueWinGroesse = winGroesse.toString() + "px";
document.querySelector('html').style.height = neueWinGroesse;
function reSizeFunkt () {
winGroesse = window.innerHeight;
neueWinGroesse = winGroesse.toString() + "px";
document.querySelector('html').style.height = neueWinGroesse;
**setTimeout(function() {
winGroesse = window.innerHeight;
neueWinGroesse = winGroesse.toString() + "px";
document.querySelector('html').style.height = neueWinGroesse;
}, 300);**
};
I figured out, that the rezise needs an moment so I set a 2nd function width a delay of 300ms. It does what it's supposed to do but I think there is a clean way
still hoping there is a real solution
推荐阅读
- c++ - std::includes 实际上是做什么的?
- ruby-on-rails - Rake db:migrate 添加默认值:nil 到所有表
- r - 如何在 R 中的数据框中删除字符串末尾的一两个单词?
- r - 在 R 中读取和写入带有彩色文本的 Excel 文件
- javascript - 永远在循环中打印数组值
- c++ - 无法编译 CGAL 代码
- php - 单独的产品图片和产品库 - Woocommerce
- ruby-on-rails - 为什么我的 git 命令不会覆盖我的本地更改?
- python - Python 从 AWS GuardDuty 获取特定的 JSON 值
- mysql - Scala Slick:MTable.getTables 返回空向量/列表