2017-01-03 77 views
0

我正在寻找在@keyframe中进行添加分配的方式。例如 我想要背景位置变化无穷大,然后继续。css3动画添加assingment到{}

.waterwave{ 
 
    background-image: url("../img/waterwave.png"); 
 
    height: 215px; 
 
    margin-top: -78px; 
 
    width: 100%; 
 
    animation-name: example; 
 
    animation-duration: 100s; 
 
    animation-timing-function: ease-in-out; 
 
    animation-iteration-count: infinite; 
 
    animation-direction: normal; 
 
} 
 
@keyframes example { 
 
    
 
    to {background-position: 100px;} 
 
}

但我不想让绝对值像100px的。 我想在js动画中使用backgroundPosition:“+ = 100”。 有没有可能在css中这样做?

谢谢

回答

0

如果您有重复背景,则位置将从背景图形的宽度开始。例如,如果图形宽度为300px,则background-position:50px看起来与background-position:350px完全相同。
这就是你可以使用的:将背景动画精确地移动到与图形相同的宽度,然后它将无缝地重新开始。至少如果你使用线性函数而不是缓出来的话。

.waterwave { 
 
    background-image: url("http://lorempixel.com/300/215"); /* a 300px wide image */ 
 
    height: 215px; 
 
    margin-top: -78px; 
 
    width: 100%; 
 
    animation-name: example; 
 
    animation-duration: 5s; 
 
    animation-timing-function: linear; /* changed from ease-in-out */ 
 
    animation-iteration-count: infinite; 
 
    animation-direction: normal; 
 
} 
 
@keyframes example { 
 
    to { 
 
    background-position: 300px;  /* this should be the same as the image */ 
 
    } 
 
}
<div class="waterwave"></div>

(在这个例子中我用了5秒的持续时间,以使效果明显,但你的想法。)