tec*_*ant 10 javascript iphone address-bar onload hide
关于此的很多帖子,但不完全符合我的情况.我的页面具有灵活的尺寸设置为100%宽度和100%高度,因此典型的有载滚动功能不起作用.任何想法或其他解决方案?
谢谢!
CSS:
* {
margin:0;
padding:0;
}
html, body {
width:100%;
height:100%;
min-width:960px;
overflow:hidden;
}
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
/mobile/i.test(navigator.userAgent) && !pageYOffset && !location.hash && setTimeout(function () {
window.scrollTo(0, 1);
}, 1000);?
Run Code Online (Sandbox Code Playgroud)
Nate Smith的这个解决方案帮助了我:如何在全屏Iphone或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);
};
Run Code Online (Sandbox Code Playgroud)
我也为此苦苦挣扎。最初,我尝试使用 CSS 类 (.stretch) 定义 200% 高度和溢出可见,然后通过 ScrollTo 之前和之后的脚本在 HTML 上切换此设置。这不起作用,因为计算出的 100% 高度指的是可用视口尺寸减去所有浏览器镶边(将状态栏恢复到位)。
\n\n最终我不得不请求特定的样式通过 DOM API 动态应用。要添加到您的附加片段:
\n\nvar CSS = document.documentElement.style;\n\n/mobile/i.test(navigator.userAgent) && !pageYOffset && !location.hash && setTimeout(function () {\n CSS.height = \'200%\';\n CSS.overflow = \'visible\';\n\n window.scrollTo(0, 1);\n\n CSS.height = window.innerHeight + \'px\';\n CSS.overflow = \'hidden\';\n}, 1000);\xe2\x80\x8b\nRun Code Online (Sandbox Code Playgroud)\n\n不过,我建议扩展 Scott Jehl 的方法,该方法解决了 Android/iOS Safari 中的细微差异:
\n\nhttps://gist.github.com/scottjehl/1183357
\n| 归档时间: |
|
| 查看次数: |
16495 次 |
| 最近记录: |