Use window.pageYOffset instead of window.scrollY