Reputation: 327
I`m making an repeatable autoscroll text.
My code look like this: http://jsfiddle.net/yjYJ4/243/
And when there is a lot of rows its starts to scroll slowly and after few seconds its stops and the speed rise quickly.
How to change code to have an constant speed when is scroll`s? Speed must be slow enought to read text.
function scroll(element, speed) {
element.animate({
scrollTop: $(document).height()
}, speed, function () {
$(this).animate({
scrollTop: 0
}, speed, scroll(element, speed));
});
}
scroll($('html, body'), 3000);
Upvotes: 1
Views: 2154
Reputation: 37701
You need to change the easing property of the animate method to 'linear' (it defaults to 'swing').
function scroll(element, speed) {
element.animate({ scrollTop: $(document).height() }, speed,'linear', function() {
$(this).animate({ scrollTop: 0 }, speed, 'linear', scroll(element, speed));
});
}
See here: http://jsfiddle.net/yjYJ4/248/
And for the duration of the animation, you should probably count the rows of the text or something similar, and make it dynamic so you don't have to worry about how much text there is.
Upvotes: 2