我正在试图动画一个div的背景位置,慢慢地,但没有它的动作.您可以在这里查看我目前的努力结果:
- @-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?
解决方法
结帐这个例子:
- <div id="content">Foreground content
- <div class="bg"></div>
- </div>
- @-webkit-keyframes MOVE-BG {
- from {
- -webkit-transform: translateX(0);
- }
- to {
- -webkit-transform: translateX(-187%);
- }
- }
- #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;
- -webkit-animation-name: MOVE-BG;
- -webkit-animation-duration: 100s;
- -webkit-animation-timing-function: linear;
- -webkit-animation-iteration-count: infinite;
- }