css - 使用平滑结果动画 CSS 背景位置(子像素动画)

标签 css animation background-image subpixel

我正在尝试为 div 的背景位置设置动画,速度很慢,但不会出现抖动。你可以在这里看到我当前努力的结果:

http://jsfiddle.net/5pVr4/2/

@-webkit-keyframes MOVE-BG {
    from {
        background-position: 0% 0%
    }
    to { 
        background-position: 187% 0%
    }
}

#content {
    width: 100%;
    height: 300px;
    background: url(http://www.gstatic.com/webp/gallery/1.jpg) 0% 0% repeat;
    text-align: center;
    font-size: 26px;
    color: #000;

    -webkit-animation-name: MOVE-BG;
    -webkit-animation-duration: 100s;
    -webkit-animation-timing-function: linear;
    -webkit-animation-iteration-count: infinite;
}

我已经研究了好几个小时了,但找不到任何可以在子像素级别缓慢而流畅地制作动画的东西。我当前的示例是根据此页面上的示例代码制作的:http://css-tricks.com/parallax-background-css3/

可以在此页面的 translate() 示例中看到我所追求的动画流畅度:

http://css-tricks.com/tale-of-animation-performance/

如果不能用背景位置来完成,有没有办法用多个 div 伪造重复背景并使用翻译移动这些 div?

最佳答案

检查这个例子:

#content {
  height: 300px;
  text-align: center;
  font-size: 26px;
  color: #000;
  position:relative;
}
.bg{
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: -1;
  background: url(http://www.gstatic.com/webp/gallery/1.jpg) 0% 0% repeat;
  animation-name: MOVE-BG;
  animation-duration: 100s;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
@keyframes MOVE-BG {
   from {
     transform: translateX(0);
   }
   to { 
     transform: translateX(-187%);
   }
}
<div id="content">Foreground content
  <div class="bg"></div>
</div>

http://jsfiddle.net/5pVr4/4/

关于css - 使用平滑结果动画 CSS 背景位置(子像素动画),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21087518/

相关文章:

css - CSS按钮悬停动画是如何工作的?

javascript - 有问题的 JQuery 悬停动画

css 背景图片不显示不是路径问题

javascript - 如何仅在分配时应用 Webkit-input-placeholder

css - 只使用移动设备和桌面媒体查询更好,还是不使用任何定义的媒体查询更好?

Android 动画嵌套 fragment

css - 对背景图像使用剪辑路径的替代方法

Android 模拟器浏览器 - 背景图像缺失

javascript - 如何正确切换图标按钮?

css - 具有 1 个绝对宽度 float 和 1 个相对 float 的相对宽度容器