Safari Mobile应用横幅会更改视口高度

时间:2018-11-14 05:46:00

标签: javascript ios css dom mobile-safari

enter image description here

地址栏下方的横幅广告正在更改高度,甚至不改变DOM的一部分。

底部的

Position: fixed元素被隐藏。

您可以通过

查看
  1. Safari - iOS smart phones中打开https://www.ounass.ae/clothing/
  2. 向下滚动以查看此应用横幅
  3. 单击Filter By按钮。

2 个答案:

答案 0 :(得分:0)

我有同样的问题,但这可能不是解决方法,而是解决方法。

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;
}

答案 1 :(得分:0)

您是否尝试过-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>