Added support for window scroll, fixed a bug when handling loading events