【问题标题】:jQuery: Where to insert the .animate step functionjQuery:在哪里插入 .animate 步骤函数
【发布时间】:2014-04-02 20:39:28
【问题描述】:

我正在尝试修改一个名为 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 函数是这样的:

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

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

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

阿基尔

【问题讨论】:

  • 不修改内核,祝你好运!
  • 真的吗?这个manual 说这只是一个添加动画参数的设置...
  • 我的意思是不修改插件的核心。

标签: javascript jquery fullpage.js


【解决方案1】:

this section in the documentation:

.animate( properties, options )

propertiesoptions 是两个对象,steps 必须是 options 上的一个属性。所以你的代码变成了

$(scrolledElement).animate(
    scrollOptions, 
    {
       duration: options.scrollingSpeed,
       easing: options.easing,
       step: function() {
          // ...
       },
       complete: function () {
          continuousVerticalFixSectionOrder();
          // ...
       }
    }
);

【讨论】:

  • 工作就像一个魅力!非常感谢,我在尝试理解文档时迷路了!谢谢!
【解决方案2】:

你可以试试这个:

            $(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);
            });

享受, 罗科

【讨论】:

  • 除了上次的 setTimeout 之外一切正常,非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多