简体   繁体   English

Velocity.js的步进功能?

[英]step function with velocity.js?

I recently switched from jQuery animations to velocity.js animations to improve performance. 我最近从jQuery动画切换到了velocity.js动画,以提高性能。 Switching was wasy because the syntax is largery the same. 切换很麻烦,因为语法大体相同。 However, using jQuery's step -function doesn't seem to work with it: 但是,使用jQuery的step -function似乎不起作用:

$(".elem").velocity({
    height:100
},{
    step:function(now,fx){
        if(wasScrolledDown) $("body").scrollDown();
    }
});

Is there something similar in velocity.js that I could use to run a function on every frame ? 在Velocity.js中是否可以使用类似的东西在每帧上运行一个函数

I have a chat application and when I animate elements' heights, I need the chat to remain scrolled down. 我有一个聊天应用程序,当我为元素的高度设置动画时,我需要使聊天保持向下滚动。 With jQuery animations my solution was to run .scrollDown() on every frame. 使用jQuery动画,我的解决方案是在每个帧上运行.scrollDown() .scrollDown() is my own extension which simply scrolls to the end of the selected element(s). .scrollDown()是我自己的扩展名,它只是滚动到所选元素的末尾。

Velocity has a progress option which is equivalent to jQuery step. Velocity有一个progress选项,相当于jQuery step。 Here is how the syntax looks like: 语法如下所示:

$element.velocity({
    opacity: 0,
    tween: 1000 // Optional
}, {
    progress: function(elements, complete, remaining, start, tweenValue) {
        console.log((complete * 100) + "%");
        console.log(remaining + "ms remaining!");
        console.log("The current tween value is " + tweenValue)
    }
});

From the doc : [Option: Progress] Pass the progress option a callback function to be repeatedly triggered througout the duration of an animation. 文档中[选项:进度]向进度选项传递回调函数,以便在整个动画过程中重复触发该回调函数。 The callback function is passed data on the status of the call. 回调函数将传递有关呼叫状态的数据。 This data can be leveraged for custom tweening and more. 此数据可用于自定义补间等。

Here is a demo that may be useful. 这是一个可能有用的演示 Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM