AutoScroll

AutoScroll - 双击切换自动滚屏

< Feedback on AutoScroll

Review: OK - script works, but has bugs

§
Posted: 22 September 2016

Thanks for the headstart

I can see where you were going with this but it didn't quite work right, for me. With a little tweak, it did. I added a speed value to the variable definitions, a Y position value, and the ability to stop, scroll, and restart where you are.

(function(document) {
var enable = false,
handler = 0,
sSpeed = 1000,
sTop,
dbclick = function() {
enable = !enable;
clearTimeout(handler);
if (enable) {
aScroll();
}
else {
sTop = undefined;
}
};

document.body.removeEventListener('dblclick', dbclick);
document.body.addEventListener('dblclick', dbclick);

var aScroll = function() {
if (enable) {
if (sTop === undefined) sTop = window.scrollY;
sTop += 3;
window.scrollTo(0, sTop);
}
handler = setTimeout(aScroll, sSpeed);
};
})(document);

Post reply

Sign in to post a reply.