2

我正在尝试修改一个名为fullpage.js的库,以便在动画发生时将每个动画步骤的值输出到控制台。

这是管理动画的实际函数:

$(scrolledElement).animate(scrollOptions, options.scrollingSpeed, options.easing, function () {
    continuousVerticalFixSectionOrder();
    $.isFunction(options.afterLoad) && !localIsResizing && options.afterLoad.call(this, anchorLink, (sectionIndex + 1));
    setTimeout(function () {
        isMoving = false;
        $.isFunction(callback) && callback.call(this);
    }, scrollDelay);
});

我的步进函数将是这样的:

step: function(){
    var currentTop = $("#superContainer").offset().top;
    console.log( "Left: ", currentTop );
};

我尝试了很多组合,但仍然没有猜到在不破坏代码的情况下将它放在哪里。

抱歉打扰,我想这是一个菜鸟问题,但我花了 4 个小时在上面没有结果。感谢大家!

阿基尔

4

2 回答 2

2

请参阅文档中的此部分

.animate( properties, options )

propertiesoptions是两个对象,并且steps必须是options. 所以你的代码变成

$(scrolledElement).animate(
    scrollOptions, 
    {
       duration: options.scrollingSpeed,
       easing: options.easing,
       step: function() {
          // ...
       },
       complete: function () {
          continuousVerticalFixSectionOrder();
          // ...
       }
    }
);
于 2014-04-02T21:35:15.957 回答
1

你可以试试这个:

            $(scrolledElement).animate(
                scrollOptions
            , { step: function(){
                        var currentTop = $("#superContainer").offset().top;
                        console.log( "Left: ", currentTop );
                        }
            }, options.scrollingSpeed, options.easing, function () {
                //fix section order from continuousVertical
                continuousVerticalFixSectionOrder();

                //callback (afterLoad) if the site is not just resizing and readjusting the slides
                $.isFunction(options.afterLoad) && !localIsResizing && options.afterLoad.call(this, anchorLink, (sectionIndex + 1));

                setTimeout(function () {
                    isMoving = false;
                    $.isFunction(callback) && callback.call(this);
                }, scrollDelay);
            });

享受吧,罗科

于 2014-04-02T21:28:47.037 回答