我找到了这个很酷的 jQuery 脚本来为标题设置动画:http://www.devirtuoso.com/2009/07/how-to-build-an-animated-header-in-jquery .但是我想稍微改变一下,但不幸的是我的脚本技能有限。
我想要做的是:当动画到达图像的末尾时,我希望它再次向上滚动,而不是像教程中那样重新开始。所以,基本上图像会不断地上下移动。
有人知道脚本会是什么样子吗?
问候
最佳答案
尝试将 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/
它所做的只是在到达循环的任一端时切换步长值。
关于jquery - jQuery 中的动画标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4987624/