css3 – 动画CSS背景位置与平滑的结果(子像素动画)

前端之家收集整理的这篇文章主要介绍了css3 – 动画CSS背景位置与平滑的结果(子像素动画)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在试图动画一个div的背景位置,慢慢地,但没有它的动作.您可以在这里查看我目前的努力结果:

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

  1. @-webkit-keyframes MOVE-BG {
  2. from {
  3. background-position: 0% 0%
  4. }
  5. to {
  6. background-position: 187% 0%
  7. }
  8. }
  9.  
  10. #content {
  11. width: 100%;
  12. height: 300px;
  13. background: url(http://www.gstatic.com/webp/gallery/1.jpg) 0% 0% repeat;
  14. text-align: center;
  15. font-size: 26px;
  16. color: #000;
  17.  
  18. -webkit-animation-name: MOVE-BG;
  19. -webkit-animation-duration: 100s;
  20. -webkit-animation-timing-function: linear;
  21. -webkit-animation-iteration-count: infinite;
  22. }

我已经在这几个小时,找不到任何将在亚像素级别缓慢而顺利的动画.我当前的例子是从这个页面上的示例代码http://css-tricks.com/parallax-background-css3/

在这个页面的translate()示例中可以看到动画的平滑度.

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

如果不能使用背景位置,是否有一种方式来伪造多个div的重复背景,并使用翻译移动这些div?

解决方法

结帐这个例子:

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

  1. <div id="content">Foreground content
  2. <div class="bg"></div>
  3. </div>
  4.  
  5. @-webkit-keyframes MOVE-BG {
  6. from {
  7. -webkit-transform: translateX(0);
  8. }
  9. to {
  10. -webkit-transform: translateX(-187%);
  11. }
  12. }
  13.  
  14. #content {
  15. height: 300px;
  16. text-align: center;
  17. font-size: 26px;
  18. color: #000;
  19. position:relative;
  20. }
  21.  
  22. .bg{
  23. position: absolute;
  24. left: 0;
  25. right: 0;
  26. top: 0;
  27. bottom: 0;
  28. z-index: -1;
  29. background: url(http://www.gstatic.com/webp/gallery/1.jpg) 0% 0% repeat;
  30.  
  31. -webkit-animation-name: MOVE-BG;
  32. -webkit-animation-duration: 100s;
  33. -webkit-animation-timing-function: linear;
  34. -webkit-animation-iteration-count: infinite;
  35. }

猜你在找的CSS相关文章