         if container.offset() != undefined
           containerTopOffset = container.offset().top
         elementBottom = elem.offset().top - containerTopOffset + elem.height()
+
+      if(useDocumentBottom)
+        elementBottom = $(document).height()
+
       remaining = elementBottom - containerBottom
       shouldScroll = remaining <= container.height() * scrollDistance + 1
 

    infiniteScrollContainer: '='
    infiniteScrollDistance: '='
    infiniteScrollDisabled: '='

  link: (scope, elem, attrs) ->
    $window = angular.element($window)

    checkWhenEnabled = null
    container = null
    immediateCheck = true
    useDocumentBottom = false

    # infinite-scroll specifies a function to call when the window,
    # or some other container specified by infinite-scroll-container,
