$ window.height不是Firefox的功能

时间:2014-06-20 04:18:54

标签: javascript jquery angularjs

我使用无限滚动指令,这是代码:

 angApp.directive('infiniteScroll', [
            '$rootScope', '$window', '$timeout', function ($rootScope, $window, $timeout) {
                return {
                    link: function (scope, elem, attrs) {
                        var checkWhenEnabled, handler, scrollDistance, scrollEnabled;
                        $window = angular.element($window);
                        scrollDistance = 0;
                        if (attrs.infiniteScrollDistance != null) {
                            scope.$watch(attrs.infiniteScrollDistance, function (value) {
                                return scrollDistance = parseInt(value, 10);
                            });
                        }
                        scrollEnabled = true;
                        checkWhenEnabled = false;
                        if (attrs.infiniteScrollDisabled != null) {
                            scope.$watch(attrs.infiniteScrollDisabled, function (value) {
                                scrollEnabled = !value;
                                if (scrollEnabled && checkWhenEnabled) {
                                    checkWhenEnabled = false;
                                    return handler();
                                }
                            });
                        }
                        handler = function () {
                            var elementBottom, remaining, shouldScroll, windowBottom;
                            console.log($window);
                            windowBottom = $window.height() + $window.scrollTop();
                            elementBottom = elem.offset().top + elem.height();
                            remaining = elementBottom - windowBottom;
                            shouldScroll = remaining <= $window.height() * scrollDistance;
                            if (shouldScroll && scrollEnabled) {
                                if ($rootScope.$$phase) {
                                    return scope.$eval(attrs.infiniteScroll);
                                } else {
                                    return scope.$apply(attrs.infiniteScroll);
                                }
                            } else if (shouldScroll) {
                                return checkWhenEnabled = true;
                            }
                        };
                        $window.on('scroll', handler);
                        scope.$on('$destroy', function () {
                            return $window.off('scroll', handler);
                        });
                        return $timeout((function () {
                            if (attrs.infiniteScrollImmediateCheck) {
                                if (scope.$eval(attrs.infiniteScrollImmediateCheck)) {
                                    return handler();
                                }
                            } else {
                                return handler();
                            }
                        }), 0);
                    }
                };
            }
    ]);

这段代码的问题有时它有时会发挥作用。如果我按Ctrl + F5进行硬刷新,则肯定会引发以下错误。

这是错误:

enter image description here

我使用的是Firefox 29.0.1。我错过了什么?

1 个答案:

答案 0 :(得分:1)

通常这应该有效,但requireJS可能存在一些问题。使用$()代替应确保使用Jquery。自normally RequireJS loads and evaluates scripts in an undetermined order.

以来,您可能需要order插件来处理requireJS