Fixed bug with events not working properly if window was scrolled