Can I update a variable by making its value a function that gets an external value every 10 milliseconds with setInterval? I'm a beginner so be kind.
var scrollTop = setInterval(function() {
var scrollTop = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
}, 10);
These are some of the observations and suggestions to improve your code,hope this will help you.
Set Interval will return an interval ID which means your var scrollTop will have an id value like(0,1,2,4) instead of an offset value.
set Interval will take a callback function means just define your function outside of the interval and use that. it will make your code cleaner and easy to debug.
also you are beginner so you can read about this terms to understand it better callback functions, setInterval, arrow function(()=>)
function offSetValue(){
var scrollTop = (window.pageYOffset !== undefined) ? window.pageYOffset :
(document.documentElement || document.body.parentNode ||
document.body).scrollTop;
}
setInterval(() => offSetValue(), 10);