'stopped'为null或不是对象

时间:2014-07-17 14:21:00

标签: javascript jquery

我正在尝试为图像添加动画效果。此动画在两个屏幕过渡之间播放。此动画用于显示等待栏。我使用的是require-jquery.js,版本是1.7.1。我收到了一个不一致的错误:

  

'stopped'为null或不是对象。

有人遇到同样的问题吗?请分享解决方案。

更新代码:

    templateFn: Handlebars.compile(
        '<div class="waitingBar"></div>'
    ),

    render: function(parent) {
        this.element = $(this.templateFn());

        this._animate();

        parent.append(this.element);
    },


_animate: function() {
    var self = this;
    this.element.animate({
        "background-position-x": "+=1024px"
    },
    8000,
    "linear",
    function () {
        self.element.css({
            "background-position-x": "-1024"
        });
        self._animate();
    });
}

我在require-jquery库中收到错误。以下是功能:  图书馆代码:

      function Animation( elem, properties, options ) {
        var result,
        stopped,
        index = 0,
        length = animationPrefilters.length,
        deferred = jQuery.Deferred().always( function() {
            // don't match elem in the :animated selector
            delete tick.elem;
         }),
         tick = function() {
            if ( stopped ) {
                return false;
            }
            var currentTime = fxNow || createFxNow(),
                remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
            // archaic crash bug won't allow us to use 1 - ( 0.5 || 0 ) (#12497)
                temp = remaining / animation.duration || 0,
                percent = 1 - temp,
                index = 0,
                length = animation.tweens.length;

            for ( ; index < length ; index++ ) {
                animation.tweens[ index ].run( percent );
            }

            deferred.notifyWith( elem, [ animation, percent, remaining ]);

            if ( percent < 1 && length ) {
                return remaining;
            } else {
                deferred.resolveWith( elem, [ animation ] );
                return false;
            }
        }

1 个答案:

答案 0 :(得分:0)

**我自己解决了....这里是解决方案:** 我有一个名为destroy()的方法,当我移动到下一页时会被调用。我在destroy()方法中停止动画(使用.stop())。我们在同一个元素上调用多个动画。后面的动画放在元素的效果队列中。这些动画直到第一个动画完成才会开始。调用.stop()时,队列中的下一个动画立即开始。但由于元素引用存在于内存中(this.element不是null),第二个动画存在于效果队列中,它会再次尝试动画,但不会找到附加到它的数据。所以在这种情况下,stop可能会变为null。因此,当它试图检查是否(停止)时,它可能会给出错误。

最后我将.stop()设置为.stop(true)来清除队列,并使this.element = null。 这两个变化似乎对我有用.....:)

相关问题