2015-10-13 132 views
-3

我在html中看到了一些补间动画的示例,但似乎无法找到符合我确切需要的明确答案。HTML 5/CSS动画 - 滚动平铺背景图像

我正在尝试制作占据100%网页高度的某个宽度的div。这个div应该有一个平铺的背景图像。

这是棘手的部分 - 我希望平铺图像在div内以可设定的速度垂直滚动。

有没有简单的解决方案呢?

+1

问题寻求帮助的代码必须包括所期望的行为,一个特定的问题或错误的和必要的重现它最短的代码**在问题本身**。请参阅[**如何创建一个最小,完整和可验证的示例**](http://stackoverflow.com/help/mcve) –

+0

不是最好的问题,但[这里是一个示例](https:// jsbin.com/zidecob/edit?html,css,output)。 – misterManSam

+0

你会如何改善这个问题。链接的网页似乎更适用于需要解决方案的问题,而不是识别算法或设计方法 – RWilco8

回答

1

您可以通过动画background-position属性来完成此操作。

body{ 
 
    background: url("https://www.google.be/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png") repeat; 
 
    -webkit-animation: scrolling 5s linear infinite; 
 
    -moz-animation: scrolling 5s linear infinite; 
 
    -o-animation: scrolling 5s linear infinite; 
 
    animation: scrolling 5s linear infinite; 
 
} 
 

 
@-webkit-keyframes scrolling { 
 
    from{ 
 
     background-position: 0 0; 
 
    } 
 
    to{ 
 
     background-position: 0 105%; 
 
    } 
 
}

+0

[不需要这些前缀](http://caniuse.com/#feat=css-animation)。 *可能需要的唯一前缀是“-webkit”。 – misterManSam

+0

这似乎只适用于Chrome,不适用于IE或Firefox。此外,它重新启动时会有轻微的跳跃 – RWilco8

+0

@ Exitcode0看看这3个问题:[1](http://stackoverflow.com/questions/20095686/jquery-animate-background-position-not-working-in - )[2](http://stackoverflow.com/questions/12340130)(http://stackoverflow.com/questions/12340130/)/jQuery的动画背景图像上,y轴)。您应该可以通过搜索一下来解决您的其他问题。 –