【发布时间】:2016-04-22 22:58:00
【问题描述】:
在我的网站部分的背景图像上使用全宽和全高,但我在 Android 上遇到了一些跳跃行为。我正在使用modernizr 来检测触摸事件并将背景附件从固定更改为本地。 Here is the site 及以下是我正在使用的 css:
.intro, .behind-the-scenes, .the-scene, .the-stage, .contact {
height: 100vh;
min-width: 100%;
color: $white;
display: table;
background-attachment: fixed;
background-position: center;
background-size: cover;
background-repeat: no-repeat;
}
// if a touchevent is detected
.touchevents {
.intro, .behind-the-scenes, .the-scene, .the-stage, .contact {
background-attachment: local;
}
}
【问题讨论】:
-
不完全确定,但我认为问题是由
height: 100vh;和background-size: cover;组合引起的。当您向下滚动时,Android Chrome 浏览器的“标题”部分会消失。所以元素变得有点高,背景图像被拉伸得更多以覆盖元素。在我的一个项目中遇到了这个问题。 -
@shirfy - 是的,我也是这么想的。我更改了背景附件:本地和高度:100%。它似乎工作得更好一些。
-
不是最好的解决方案,但我会保留 css 并在页面加载后使用 js 设置元素的高度。
-
是的,这似乎成功了。
-
如果这对您的情况来说是一个足够好的解决方案,那么我会写一个答案。
标签: android css background-image viewport-units background-attachment