Created
June 29, 2020 21:00
-
-
Save celestelayne/131d2b09478cfe8bd3f526b19b2aa1c6 to your computer and use it in GitHub Desktop.
celeste-layne-brown-institute
This file contains 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 characters
class MyAnalytics { | |
constructor(){ | |
} | |
pageLoad() { | |
fetch("https://httpbin.org/get?click=1&type=page-views") | |
.then(response => response.json()) | |
.then(data => console.log("pageLoad request sent")); | |
} | |
scroll20() { | |
fetch("https://httpbin.org/get?click=1&type=page-views") | |
.then(response => response.json()) | |
.then(data => console.log("scroll20 request sent")); | |
} | |
} | |
function getScrollPercent() { | |
var h = document.xdocumentElement, | |
b = document.body, | |
st = 'scrollTop', | |
sh = 'scrollHeight'; | |
return (h[st]||b[st]) / ((h[sh]||b[sh]) - h.clientHeight) * 100; | |
} | |
window.addEventListener("scroll", function(e){ | |
// console.log(e) | |
if(getScrollPercent() > 20){ | |
run.scroll20() | |
} else { | |
} | |
}); | |
let run = new MyAnalytics; | |
run.pageLoad() | |
run.scroll20() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment