In SharePoint $(window).scroll() event is not firing because code is load in master page web part zone. SharePoint master page doesn’t use the scrolling on the “body” tag.
Add scroll event on div tag with ID=”s4-workspace”. Replace $(window).scroll() code with something like bellow
$(‘#s4-workspace’).scroll(function() {
alert(‘Hi’);
});
Related Article: