Safari:修正了背景+过渡

时间:2013-05-22 15:11:43

标签: macos webkit css-transitions safari

Example site

我有一个网站分为您通常的垂直部分。页眉和页脚都包含背景附件的背景:固定。我有一个滑出式导航,您可以在第一个链接上看到它。除了......之外,一切都很花哨。

问题: Safari 6(我不确定5.1,但它似乎在Mac上,因为我的Windows Safari没有问题)动画上有一个令人讨厌的闪烁。这可以用通常的-webkit-backface hack解决,但是在使用它时,会出现一个新问题。固定的背景图像开始表现非常糟糕,如果您足够滚动/调整浏览器大小,图像会失真或内容叠加不正确。是否有替代方法可用于此技术或实际修复?

HTML

<section>Hi <a href="#">CLICKME</a></section>
<section>hi</section>
<section>hi</section>
<section>hi</section>
<footer><p>I am some text</p></footer>
<aside class="menu">
  I'm a menu.
</aside>

CSS

body {
  background: #222;
  transition: all 0.3s;
  -webkit-backface-visibility: hidden;
}

body.bump {
  transform: translate(-258px, 0);
}

section {
  background: #CBA;
  color: white;
  line-height: 450px;
  font-size: 32px;
  height: 500px;
  position: relative;
  text-align: center;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
  z-index: 1;
}
section:nth-child(2) {
  background: #FAFAFA;
}
section:nth-child(3) {
  background: #CCC;
}
section:nth-child(4) {
  background: #ABC;
}

section:first-child {
  background: url(http://placekitten.com/1600/500) center top;
  background-attachment: fixed;
  -webkit-backface-visibility: hidden;
}
@media all and (min-width: 73.75em) {
  section:first-child {
    background-size: cover;
  }
}

footer {
  background: url(http://placekitten.com/1400/500) center top;
  background-attachment: fixed;
  color: white;
  font-size: 32px;
  height: 500px;
}
@media all and (min-width: 73.75em) {
  footer {
    background-size: cover;
  }
}
footer p {
  position: fixed;
  bottom: 200px;
  left: 0;
  text-align: center;
  width: 100%;
}

aside.menu {
  background: #222;
  color: #FFF;
  height: 100%;
  padding-top: 30px;
  position: fixed;
  top: 0;
  right: 0;
  text-align: left;
  transform: translate(516px, 0);
  transition: all 0.3s;
  width: 258px;
  -webkit-backface-visibility: hidden;
}

.bump aside.menu {
  transform: translate(258px, 0);
}

JS(使用Jquery)

$('section a').click( function(e) {
  $('body').toggleClass('bump');
});

1 个答案:

答案 0 :(得分:0)

我做了一个解决方法,通过将固定的背景应用到身体,将所有内容包裹在另一个div中(相反,动画,因此它不影响身体背景)并且页脚保持不变,因为滚动了到目前为止,无论如何都无法弹出侧边栏(因此无需担心动画闪烁)。