I had a similar problem in my case. This code is correct, but did not work because,
window.addEventListener("scroll", function () { myFunc(); }, false);
the scroll event did not fire. since my body was scrolling instead of documentElement.
I just removed height: 100% from my body tag, and then the scroll event started.
Vikramaditya
source share