Modified to support listening to scroll events on any element, not just the window.