![](/img/trans.png)
[英]How to calculate the multiplication factor for scroll speed on another element so that they both reach end at the same time (top of view)
[英]Infinite auto scroll top-to-bottom and back, how to control/configure speed, time of pause at end?
我正在嘗試使一長頁圖像無限地上下滾動(用於展覽)。
這就是我一直在使用的代碼(在這里找到的代碼非常有用!): https : //jsfiddle.net/p7r73tke/
基本上可以滿足我的需求,但我需要對速度和暫停進行更多控制。
如何使頂部的停頓時間更長?
有沒有辦法讓它隨機暫停約1秒鍾?
有誰知道做我在想什么的更簡單方法? 也許正如samuel-liew建議的那樣,javascript並不是解決問題的最佳方法
謝謝,謝謝!
function scrollpage() {
function f() {
window.scrollTo(0, i); //idk
if (status == 0) {
i = i + 50; //scroll speed top to bottom?
if (i >= Height) {
status = 30; //idk?
}
} else {
i = i - 10; //scroll speed bottom to top?
if (i <= 1) { // if you don't want continue scroll then remove this if condition
status = 0; //idk
}
}
setTimeout(f, 0.01); //idk
}
f();
}
var Height = 15000; //doc height input manually
var i = 1, //idk
j = Height,
status = 0; //idk
scrollpage();
(我是新手,對JavaScript很溫柔,正如您在評論中看到的那樣)
謝謝你的幫助!
jQuery解決方案:
var speed = 10000; // 10000 = 10 seconds
var doScroll = function() {
var direction = $(window).scrollTop() != 0 ? 0 : $(document).height() - $(window).height();
$('html, body').animate({ scrollTop: direction }, speed, 'linear');
}
doScroll(); // once on page load
setInterval(doScroll, speed + 10); // once every X ms
演示: http : //jsfiddle.net/samliew/k35tbgau/
JavaScript的:
抱歉,我不建議您使用純JavaScript,因為您必須考慮以下因素:
考慮用戶是否手動滾動滾動條
可能還有更多...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.