summaryrefslogtreecommitdiff
path: root/crocoite/data/scroll.js
diff options
context:
space:
mode:
Diffstat (limited to 'crocoite/data/scroll.js')
-rw-r--r--crocoite/data/scroll.js41
1 files changed, 31 insertions, 10 deletions
diff --git a/crocoite/data/scroll.js b/crocoite/data/scroll.js
index 0d1a4a7..be88edf 100644
--- a/crocoite/data/scroll.js
+++ b/crocoite/data/scroll.js
@@ -1,17 +1,38 @@
/* Continuously scrolls the page
*/
-var __crocoite_stop__ = false;
(function(){
-function scroll (event) {
- if (__crocoite_stop__) {
- return false;
- } else {
+class Scroll {
+ constructor (options) {
+ this.scrolled = new Map ();
+ this.interval = window.setInterval (this.scroll.bind (this), 200);
+ }
+
+ stop() {
+ window.clearInterval (this.interval);
+ window.scrollTo (0, 0);
+ this.scrolled.forEach (function (value, key, map) {
+ key.scrollTop = value;
+ });
+ }
+ /* save initial scroll state */
+ save(obj) {
+ if (!this.scrolled.has (obj)) {
+ this.scrolled.set (obj, obj.scrollTop);
+ }
+ }
+ /* perform a single scroll step */
+ scroll (event) {
window.scrollBy (0, window.innerHeight/2);
+ document.querySelectorAll ('html body *').forEach (
+ function (d) {
+ if (d.scrollHeight-d.scrollTop > d.clientHeight) {
+ this.save (d);
+ d.scrollBy (0, d.clientHeight/2);
+ }
+ }.bind (this));
return true;
}
}
-function onload (event) {
- window.setInterval (scroll, 200);
-}
-document.addEventListener("DOMContentLoaded", onload);
-}());
+
+return Scroll;
+}())