目前示例中的speed
和step
都是1
。但我需要更慢的滚动速度。如何完全控制速度。
我想让云移动得慢一些
示例
代码
(function($) {
$.fn.scrollingBackground = function(options) {
// settings and defaults.
var settings = options || {};
var speed = settings.speed || 1;
var step = settings.step || 1;
var direction = settings.direction || 'rtl';
var animStep;
// build up a string to pass to animate:
if (direction === 'rtl') {
animStep = "-=" + step + "px";
}
else if (direction === 'ltr') {
animStep = '+=' + step + "px";
}
var element = this;
// perform the animation forever:
var animate = function() {
element.animate({
backgroundPosition: animStep + " 0px"
}, speed, animate);
};
animate();
};
})(jQuery);
$("#header").scrollingBackground({
speed: 1,
step: 1,
direction: 'ltr'
});
$("#header-2").scrollingBackground({
speed: 1,
step: 1,
direction: 'rtl'
});
最佳答案
如果增加 speed
属性会减慢滚动速度,因为它会增加步骤之间的延迟。我尝试了 100 的值,它看起来仍然很平滑。
关于javascript - 如何在此 jQuery 滚动脚本中使滚动速度变慢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4687915/