Safari Mobile 应用程序横幅更改视口高度
Safari Mobile app banner changes the viewport height
地址栏下方的横幅正在改变高度,甚至不是DOM的一部分。
Position: fixed
底部的元素被隐藏。
您可以通过
查看
- 在
Safari - iOS smart phones
中打开 https://www.ounass.ae/clothing/
- 向下滚动查看此应用横幅
- 单击
Filter By
按钮。
我遇到了同样的问题,但这可能不是解决方法,而是一种解决方法。
const updatePositionOfCtaButton = () => {
if (
window.navigator.userAgent.toLowerCase().includes('safari') &&
window.navigator.userAgent.toLowerCase().includes('mobile') &&
document.documentElement.clientHeight > window.innerHeight &&
!document.hidden
) {
document.querySelector('.callToActionButton').style.bottom = '44px';
} else {
document.querySelector('.callToActionButton').removeAttribute('style');
}
}
window.addEventListener('scroll', updatePositionOfCtaButton);
document.addEventListener('visibilitychange', updatePositionOfCtaButton);
我们还可以在 CTA 按钮中添加 transition
来添加一点动画
.callToActionButton {
transition: bottom 0.16s linear 0s;
}
你试过了吗-webkit-fill-available
html {
height: -webkit-fill-available;
}
body {
display: flex;
flex-direction: column;
margin: 0;
min-height: 100vh;
/* mobile viewport bug fix */
min-height: -webkit-fill-available;
}
main {
flex: 1;
}
<header>HEADER GOES HERE</header>
<main>MAIN GOES HERE</main>
<footer>FOOTER GOES HERE</footer>
地址栏下方的横幅正在改变高度,甚至不是DOM的一部分。
Position: fixed
底部的元素被隐藏。
您可以通过
查看- 在
Safari - iOS smart phones
中打开 https://www.ounass.ae/clothing/
- 向下滚动查看此应用横幅
- 单击
Filter By
按钮。
我遇到了同样的问题,但这可能不是解决方法,而是一种解决方法。
const updatePositionOfCtaButton = () => {
if (
window.navigator.userAgent.toLowerCase().includes('safari') &&
window.navigator.userAgent.toLowerCase().includes('mobile') &&
document.documentElement.clientHeight > window.innerHeight &&
!document.hidden
) {
document.querySelector('.callToActionButton').style.bottom = '44px';
} else {
document.querySelector('.callToActionButton').removeAttribute('style');
}
}
window.addEventListener('scroll', updatePositionOfCtaButton);
document.addEventListener('visibilitychange', updatePositionOfCtaButton);
我们还可以在 CTA 按钮中添加 transition
来添加一点动画
.callToActionButton {
transition: bottom 0.16s linear 0s;
}
你试过了吗-webkit-fill-available
html {
height: -webkit-fill-available;
}
body {
display: flex;
flex-direction: column;
margin: 0;
min-height: 100vh;
/* mobile viewport bug fix */
min-height: -webkit-fill-available;
}
main {
flex: 1;
}
<header>HEADER GOES HERE</header>
<main>MAIN GOES HERE</main>
<footer>FOOTER GOES HERE</footer>