当在ios上滚动时,固定背景上的白色区域 [英] White area on fixed background when scrolling on ios
问题描述
我的目标是在iOS / Android上具有缩放的背景,在用户向下滚动(并且地址栏消失)后不必重新缩放。我发现几个问题有用的答案,但不知怎的,我在我的iPhone上一直有恼人的行为。我使用Bootstrap。
My aim is to have a scaled background on iOS/Android that doesn't have to rescale after user scrolls down (and the address bar disappears). I found several questions with useful answers but somehow I keep having annoying behaviour on my iPhone. I use Bootstrap.
这是我的简化HTML
Here's my simplified HTML
<html>
<body>
<div id="background-img"></div>
<div id="layout" class="container">
<div id="content-main" class="col-xs-12">
<p>Some text here</p>
</div>
</div>
</body>
</html>
这是我的css
html {
height: 100%; }
body {
position: relative;
/* required for scrollspy */
font-family: Arial, Helvetica, Sans-Serif;
font-size: 30px;
font-weight: normal;
height: 100%;
color: white;
overflow: scroll;
-webkit-overflow-scrolling: touch;
/* smooth scrolling on ios */ }
#background-img {
width: 100%;
top: 0;
left: 0;
bottom: -80px;
position: fixed;
z-index: -1;
background: url("http://www.casapanorama.nl/sites/all/themes/casapanorama/images/bg-klaprozen-1-w1000.jpg") no-repeat center center;
background-size: cover;
}
#content-main { //nothing fancy }
罚款在桌面上。但是当我在ios上打开网站(chrome或safari - 没有区别),当我向下滚动屏幕的底部,我得到一个白色的酒吧。当滚动停止时,该条消失。您可以在移动设备上自行尝试: https://jsbin.com/rudetokoxu
Everything runs fine on desktop. But when I open the site on ios (chrome or safari - makes no difference) I get a white bar on the bottom of the screen when I scroll down. The bar disappears when scrolling has stopped. You can try it yourself on mobile at: https://jsbin.com/rudetokoxu
我试过解决方案贴在这里:
。这里的解决方案似乎是合乎逻辑的。我甚至尝试将背景div的高度设置为200%,但无效。
I tried solutions posted here: CSS background stretches to fill height in iOS but there is white space on scroll. Solution here seems logical. I even tried setting the height of the background div to 200% but to no avail.
也尝试:
移动IOS Google Chrome地址栏行为
,其中:
地址栏隐藏iOS / Android /移动Chrome时背景图片会跳转
包括js解决方案(似乎他们中的一些没有工作,所以我没有尝试所有的js解决方案)和任何其他我可以找到的主题
Also tried: mobile IOS Google chrome address bar behaviour and here: Background image jumps when address bar hides iOS/Android/Mobile Chrome including the js solutions (it seemed that some of them did not work anymore so I did not try all the js solutions) and anything else I could find on the subject
请帮助我解决这个问题,或说服我永远不要两次思考这些恼人的小事情(生活充满了他们:-))
Please help me solve this or convince me never to think twice about anoying little things like these (cos life is full of them :-) )
此网站在移动设备上也有相同的问题: http://www.laregiondesmusees.fr ,但此网站没有遭受: http://www.heartkids.co.nz
BTW: this site has the same problem on mobile: http://www.laregiondesmusees.fr, but this site does not suffer: http://www.heartkids.co.nz
推荐答案
我感到你的痛苦。如果您仔细查看示例,您发现没有空格问题( http://www.heartkids.co。 nz ) - 答案在那里,但很难找到,除非你知道你在找什么。
I feel your pain. If you look carefully at the example you found where there was no white space problem (http://www.heartkids.co.nz) - the answer was there, but hard to find unless you know what you are looking for.
您会看到他们对背景图片应用了2d变换。在大多数情况下,对具有背景图像的固定div应用二维或三维变换可以消除不必要的白色空间。
You'll see they applied a 2d transform on the background image. In most cases applying either a 2d or a 3d transform on fixed divs with background images gets rid of unwanted white space like this.
这个CSS应该删除那个恼人的白色条。干杯。
This CSS should remove that annoying white bar. Cheers.
.background-img {
transform: translate3d(0,0,0);
}
这篇关于当在ios上滚动时,固定背景上的白色区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!