Я хочу, чтобы страница прокручивалась медленно и плавно. Ну, скорость должна фактически регулироваться. Пользователь также должен иметь возможность прокручивать вручную, пока script прокручивается вниз. Сначала я попробовал это:
var autoScrollDelay = 1
var autoScrollSpeed = 1
var autoScrollTimer
function setAutoScroll(newValue) {
autoScrollSpeed = newValue ? newValue : autoScrollSpeed
if (autoScrollTimer) {
clearInterval(autoScrollTimer)
}
if (autoScrollDelay) {
autoScrollTimer = setInterval(function(){
window.scrollBy(0,autoScrollSpeed)
},autoScrollDelay)
}
}
setAutoScroll(1) // higher number = faster scrolling
Но это вызывало очень тяжелую загрузку процессора, а самая медленная скорость была слишком быстрой. И в дополнение к этому ручная прокрутка не работала должным образом во время работы кода.
Затем я попытался:
var autoScrollDelay = 1
var autoScrollSpeed = 1
var autoScrollTimer
function setAutoScroll(newValue) {
autoScrollDelay = newValue ? newValue : autoScrollDelay //using autoScrollDelay instead of autoScrollSpeed
if (autoScrollTimer) {
clearInterval(autoScrollTimer)
}
if (autoScrollDelay) {
autoScrollTimer = setInterval(function(){
window.scrollBy(0,autoScrollSpeed)
},autoScrollDelay)
}
}
setAutoScroll(200) // higher number scrolls slower
Но прокрутка была негладкой при слишком медленной настройке (например, 200).
Затем я попытался:
$("html, body").animate({
scrollTop: $('html, body').get(0).scrollHeight,
}, 40000, "linear");
Но опять-таки загрузка процессора была неоправданно высокой, и прокрутка вверх или вниз вручную не была возможна таким образом.
Есть ли лучший способ сделать это?