fixed TypeError 'undefined' while scrolling to the top edge on macs

Because of the mac specific possibility to scroll over the viewport edges, TypeErrors are thrown. This fix prevents these errors.