summaryrefslogtreecommitdiff
path: root/crocoite/data
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2018-11-25 09:42:13 +0100
committerLars-Dominik Braun <lars@6xq.net>2018-11-25 09:54:14 +0100
commit2be982d477c5ffdeafea95ba14569a05da59cb0d (patch)
treef4ce80c38d8515610e41e35246f5fdd7b995e74a /crocoite/data
parentb0a66f3502b7959aed19c25dad1f2deb86f7208d (diff)
downloadcrocoite-2be982d477c5ffdeafea95ba14569a05da59cb0d.tar.gz
crocoite-2be982d477c5ffdeafea95ba14569a05da59cb0d.tar.bz2
crocoite-2be982d477c5ffdeafea95ba14569a05da59cb0d.zip
behavior: Turn scroll JS code into class
Diffstat (limited to 'crocoite/data')
-rw-r--r--crocoite/data/scroll.js57
1 files changed, 31 insertions, 26 deletions
diff --git a/crocoite/data/scroll.js b/crocoite/data/scroll.js
index 8a4b35d..aacfe83 100644
--- a/crocoite/data/scroll.js
+++ b/crocoite/data/scroll.js
@@ -1,33 +1,38 @@
/* 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);
+class Scroll {
+ constructor () {
+ this.scrolled = new Map ();
+ this.interval = window.setInterval (this.scroll.bind (this), 200);
}
-}
-/* perform a single scroll step */
-function scroll (event) {
- window.scrollBy (0, window.innerHeight/2);
- document.querySelectorAll ('html body *').forEach (
- function (d) {
- if (d.scrollHeight-d.scrollTop > d.clientHeight) {
- save (d);
- d.scrollBy (0, d.clientHeight/2);
- }
+
+ stop() {
+ window.clearInterval (this.interval);
+ window.scrollTo (0, 0);
+ this.scrolled.forEach (function (value, key, map) {
+ key.scrollTop = value;
});
- return true;
+ }
+ /* 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;
+ }
}
-interval = window.setInterval (scroll, 200);
-return {'stop': stop};
+
+return new Scroll();
}())