隐藏 iPhone 地址栏,高度为 100%
关于此的很多帖子,但不完全适合我的情况。我的页面的灵活尺寸设置为 100% 宽度和 100% 高度,因此典型的加载滚动功能不起作用。有什么想法或其他解决方案吗?
谢谢!
CSS:
* {
margin:0;
padding:0;
}
html, body {
width:100%;
height:100%;
min-width:960px;
overflow:hidden;
}
JavaScript:
/mobile/i.test(navigator.userAgent) && !pageYOffset && !location.hash && setTimeout(function () {
window.scrollTo(0, 1);
}, 1000);
Many posts on this, but not quite for my situation. My page has flexible dimensions set to 100% width and 100% height, so the typical on-load scroll function isn't working. Any thoughts or other solutions?
Thanks!
CSS:
* {
margin:0;
padding:0;
}
html, body {
width:100%;
height:100%;
min-width:960px;
overflow:hidden;
}
Javascript:
/mobile/i.test(navigator.userAgent) && !pageYOffset && !location.hash && setTimeout(function () {
window.scrollTo(0, 1);
}, 1000);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Nate Smith 的这个解决方案帮助了我:如何在全屏 Iphone 或 Android Web 应用程序中隐藏地址栏。
这是要点:
有关更多详细信息,请查看他的 博客文章或要点。
This solution from Nate Smith helped me: How to Hide the Address Bar in a Full Screen Iphone or Android Web App.
Here's the essential bit:
For more details, check out his blog post or the Gist.
我也为此苦苦挣扎。最初,我尝试使用 CSS 类 (.stretch) 定义 200% 高度和溢出可见,然后通过 ScrollTo 之前和之后的脚本在 HTML 上切换此设置。这不起作用,因为计算出的 100% 高度指的是可用视口尺寸减去所有浏览器镶边(将状态栏恢复到位)。
最终我不得不请求特定的样式通过 DOM API 动态应用。要添加到您的附加代码段:
不过,我建议扩展 Scott Jehl 的方法,该方法解决了 Android/iOS Safari 的较小滚动差异:
https://gist.github.com/scottjehl/1183357
I struggled with this too. Initially I tried a CSS class (.stretch) defining 200% height and overflow visible, then toggling this on the HTML via script before and after the scrollTo. This doesn't work because the computed 100% height refers back to the available viewport dimensions minus all browser chrome (snapping the status bar back into place).
Eventually I had to request specific styles to apply dynamically via the DOM API. To add to your additional snippet:
However I'd recommend extending Scott Jehl's method, which addresses minor Android/iOS Safari scrollTo differences:
https://gist.github.com/scottjehl/1183357