慢慢地滑动页面背景图像

时间:2012-11-14 23:49:27

标签: jquery css css3 css-transitions

我正在尝试使用背景图像制作一个suttle效果。我试图让它向左移动非常慢,然后在看到整个图像后停止。

目前图像根本没有移动。

<!DOCTYPE html>
<html>
<head>
<style> 
body
{
width:100%;
height:100px;
top:0;
background-image:url('http://upload.wikimedia.org/wikipedia/commons/0/0c/Yercaud_scenery.jpg');
position:relative;
-webkit-animation:mymove 4s infinite; /* Safari and Chrome */
}


@-webkit-keyframes mymove /* Safari and Chrome */
{
0%   {top:0px;left:-70px;}
25%  {top:0px;left:-50px;}
75%  {top:0px;left:30px;}
100% {top:0px;left:31px}
}

</style>
</head>
<body>

<p>here is some sample text</p>



</body>
</html>

非常感谢任何帮助。 我不一定只使用css,但如果可能的话会更喜欢。

1 个答案:

答案 0 :(得分:2)

我没有通过css使用关键帧,而是想要更轻松,更简单的东西。我似乎找到了一个解决方案,涉及使用几行jquery&amp;的CSS。

Javascript:

<script>
$(function(){
$("body").animate({backgroundPositionX : "-450"}, 25000);
});
</script>

CSS:

<style type="text/css">
  body {
    background-image: url('../imgs/bg-image.jpg');
    background-repeat:repeat-x;
    }
</style>