简体   繁体   English

iOS 智能横幅导致底部工具栏与固定在屏幕底部的元素重叠

[英]iOS Smart Banner Causes Bottom Toolbar to Overlap Elements which are Fixed to Bottom of Screen

I have been searching for the best part of a day in order to try and find a way around this but cant.我一直在寻找一天中最好的部分,以尝试找到解决此问题的方法,但无法解决。 So here I am.所以我在这里。

Basically I am working on a component which is position: fixed;基本上我正在研究一个组件,它是position: fixed; to the bottom of the mobile browser's viewport window.移动浏览器视口 window 的底部。 This is trivial in itself.这本身就是微不足道的。

The issue is that the company's native iOS app has an Apple association file which presents the Apple smart banner to open the native app at the top of the page.问题是该公司的原生 iOS 应用程序有一个 Apple 关联文件,该文件显示 Apple 智能横幅以在页面顶部打开原生应用程序。

When this is presented to the end user it seems that the browser redefines what it classes as the bottom of the page and, as a result, anything which is fixed to the bottom of the page is overlapped by the navigation toolbar which appears.当这呈现给最终用户时,浏览器似乎重新定义了它作为页面底部的分类,因此,任何固定在页面底部的东西都会被出现的导航工具栏覆盖。

The only solution I can think of is to write out a list of all Apple mobile device viewport sizes and then compare the size of the window.innerHeight value on the onresize event -- which seems like absolute overkill and still has some nuance in itself.我能想到的唯一解决方案是写出所有 Apple 移动设备视口大小的列表,然后比较onresize事件上的window.innerHeight值的大小——这似乎绝对是矫枉过正,而且本身仍然有一些细微差别。

I have added some screen shots to illustrate the problem and what I would like to achieve.我添加了一些屏幕截图来说明问题以及我想要实现的目标。

期望的结果

实际发生了什么

Thank you in advance to anyone who can assist with this.提前感谢任何可以提供帮助的人。 I have searched through the answers to other questions but they all seem to be people either trying to surface a smart banner or people trying to redirect to their app.我已经搜索了其他问题的答案,但他们似乎都是试图展示智能横幅或试图重定向到他们的应用程序的人。

I have managed to find a solution by leveraging the resize event in the document window and then setting the top attribute of the element to window.innerHeight - element.clientHeight .通过利用文档 window 中的调整大小事件,然后将元素的top属性设置为window.innerHeight - element.clientHeight ,我设法找到了解决方案。

If there is a better, more performant way of achieving this I would love to still hear the answer but I will, for all intents and purposes, mark this as answered.如果有更好、更高效的方法来实现这一点,我仍然希望听到答案,但出于所有意图和目的,我会将其标记为已回答。

On a side note this does feel like a bug in the Safari browser itself as it seems that Apple are altering what they consider to be the bottom of the document.在旁注中,这确实感觉像是 Safari 浏览器本身的一个错误,因为苹果似乎正在改变他们认为是文档bottom的内容。

Solution:解决方案:

window.onresize = () => {
  const button = document.querySelector(".add-to-bag--sticky");
  if (button) {
    button.style.top = `${window.innerHeight - button.clientHeight}px`;
  }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM