Created
December 27, 2017 23:02
-
-
Save simonrw/679c1e4a308fd8c61b1e4f562eb3f2b8 to your computer and use it in GitHub Desktop.
Revisions
-
simonrw created this gist
Dec 27, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ <!doctype html> <html> <head> <meta charset="utf8"> <style> div#main { border: 1px solid black; display: inline-block; width: 1024px; max-width: 1024px; height: 1024px; max-height: 1024px; } </style> </head> <body> <div id="main"></div> <script type="text/javascript"> class ScrollPoster { constructor(url) { this.url = url; this.isScrolling = null; this.init(); } post(location, position) { console.log('Posting: ', { href: location.href, pos: position }); } init() { var self = this; window.addEventListener('scroll', function(e) { window.clearTimeout(this.isScrolling); this.isScrolling = setTimeout(function() { const pos = window.scrollY; self.post(window.location, pos); }, 333); }, false); } }; window.onload = () => { const handler = new ScrollPoster('http://example.com'); }; </script> </body> </html>