【问题标题】:Safari: Fixed background + transitionSafari:固定背景+过渡
【发布时间】:2013-05-17 17:20:23
【问题描述】:

Example site

我有一个网站,分为您常用的垂直部分。页眉和页脚都包含带有 background-attachment: 固定的背景。我有一个滑出式导航,您可以看到它在第一个链接上被激活。一切都很好,除了...

问题: 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');
});

【问题讨论】:

    标签: macos webkit css-transitions safari


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-07
      • 1970-01-01
      • 2013-10-06
      • 2018-11-23
      • 2018-01-20
      • 2020-05-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多