summaryrefslogtreecommitdiff
path: root/crocoite/data/scroll.js
blob: e1fbbcb00e1966406c1f8769884900be28702985 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*	Continuously scrolls the page
 */
(function(){
let scrolled = new Map ();
let interval = null;
function stop() {
	window.clearInterval (interval);
	window.scrollTo (0, 0);
	scrolled.forEach (function (value, key, map) {
		key.scrollTop = value;
	});
}
/* save initial scroll state */
function save(obj) {
	if (!scrolled.has (obj)) {
		scrolled.set (obj, obj.scrollTop);
	}
}
/* perform a single scroll step */
function scroll (event) {
	window.scrollBy (0, window.innerHeight/2);
	document.querySelectorAll ('*').forEach (
		function (d) {
			if (d.scrollHeight-d.scrollTop > d.clientHeight) {
				save (d);
				d.scrollBy (0, d.clientHeight/2);
			}
		});
	return true;
}
interval = window.setInterval (scroll, 200);
return {'stop': stop};
}())