2011-02-13 41 views
0

我发现了这个很酷的jQuery脚本,用于动画标题:http://www.devirtuoso.com/2009/07/how-to-build-an-animated-header-in-jquery。不过,我想稍微改变一下,但不幸的是我的脚本编写技巧是有限的。jQuery中的动画标题

我想要做的是:当动画到达图像的末尾时,我希望它再次向上滚动,而不是像教程中那样重新开始。所以,基本上图像会不断上下移动。

任何人都知道如何看起来像脚本明智吗?

问候

回答

0

尝试改变scrollBg()函数来此:

function scrollBg(){ 

//Go to next pixel row. 
current -= step; 

//If at the end of the image, then go to the top. 
if (current == restartPosition){ 
    step = -1; 
} else if (current == 0) { 
    step = 1; 
} 

//Set the CSS of the header. 
$('#header').css("background-position","0 "+current+"px"); 
} 

这里是一个非常基本的工作示例(只用于演示目的 - 用上面的代码):http://jsfiddle.net/lukemartin/u2XJ8/

所有它会在到达周期结束时切换步长值。

+0

谢谢!我正在尝试类似的东西,但它没有奏效。你的小片段完美无缺! – Joachim 2011-02-14 11:04:19