javascript - 隐藏 100% 高度的 iPhone 地址栏

标签 javascript iphone hide onload address-bar

关于此的很多帖子,但不完全适合我的情况。我的页面将灵活的尺寸设置为 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);​

最佳答案

Nate Smith 的这个解决方案帮助了我:How to Hide the Address Bar in a Full Screen Iphone or Android Web App .

这是最重要的部分:

var page   = document.getElementById('page'),
    ua     = navigator.userAgent,
    iphone = ~ua.indexOf('iPhone') || ~ua.indexOf('iPod');

var setupScroll = window.onload = function() {
  // Start out by adding the height of the location bar to the width, so that
  // we can scroll past it
  if (ios) {
    // iOS reliably returns the innerWindow size for documentElement.clientHeight
    // but window.innerHeight is sometimes the wrong value after rotating
    // the orientation
    var height = document.documentElement.clientHeight;
    // Only add extra padding to the height on iphone / ipod, since the ipad
    // browser doesn't scroll off the location bar.
    if (iphone && !fullscreen) height += 60;
    page.style.height = height + 'px';
  }
  // Scroll after a timeout, since iOS will scroll to the top of the page
  // after it fires the onload event
  setTimeout(scrollTo, 0, 0, 1);
};

有关更多详细信息,请查看他的 blog postGist .

关于javascript - 隐藏 100% 高度的 iPhone 地址栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5206811/

相关文章:

css - 悬停时隐藏绝对定位的div

jquery - 当我在导航栏上隐藏元素时,如何修复导航栏中剩余元素发生的 "jump"?

javascript - 将 Electron 与 Reactstrap 一起使用会导致错误 : Uncaught SyntaxError: Unexpected token :

javascript - 重置 React 中控件的默认值

iphone - UIViewContentModeScaleAspectFit 不适用于 UIScrollView subview UIImageView

ios - 检查 NSDictionary 中的键 - 不使用 bool NSNumber 作为值 @iOS8

javascript - 如何处理Backbone中的动态属性并同步到数据库

javascript - 是否可以从 powerpoint 中提取幻灯片并使用 node.js 将它们保存为图像?

iphone - 暂停申请

JavaScript:未捕获类型错误:无法读取 null 的属性 'style'