我是这样处理的。使用我自己的position:fixed;bottom:0 工具栏,我在 safari 工具栏被隐藏后不久向它添加 44px 偏移量(带有半透明缓冲区)(因为这是靠近底部的点击将显示工具栏的场景再次)。
var min_inner_height = false;
var max_inner_height = false;
var passiveIfSupported = false;
try {
window.addEventListener("test", null, Object.defineProperty({}, "passive", {
get: function () {
passiveIfSupported = {
passive: true
};
}
}));
} catch (err) {}
document.addEventListener('scroll', function (e) {
var win_inner_h = window.innerHeight;
if (/iPad|iPhone|iPod/.test(navigator.userAgent)) {
if (min_inner_height === false || win_inner_h < min_inner_height) {
min_inner_height = win_inner_h;
}
if ((max_inner_height === false || win_inner_h > max_inner_height) && win_inner_h > min_inner_height) {
max_inner_height = win_inner_h;
}
if (max_inner_height !== false && max_inner_height == win_inner_h) {
addElementClass(document.body, 'safari-toolbars-hidden');
} else {
removeElementClass(document.body, 'safari-toolbars-hidden');
}
}
}, passiveIfSupported);
这基本上将.safari-toolbars-hidden 类添加到<body> 中,因为用户向下滚动页面时它们会消失。
此时,我将自己的工具栏向上移动:
.my-bottom-toolbar {
bottom: 0px;
position: fixed;
}
@supports (-webkit-overflow-scrolling: touch) {
/* CSS specific to iOS devices */
.my-bottom-toolbar {
box-shadow: 0 44px 0 rgba(255, 255, 255, 0.8);
transition: bottom 0.15s ease-in-out;
}
.safari-toolbars-hidden .my-bottom-toolbar {
bottom: 44px;
}
}
希望这对某人有所帮助!
除了进一步偏移 44 像素外,您还可以添加额外 44 像素的底部填充,如果这对您的情况更有效。