JQuery animation: Is it possible to change speed during the animation?

我怕爱的太早我们不能终老 提交于 2019-12-11 02:09:31

问题


I want to move a div down a page, and I want it to slow down as it reaches the target.

I tried using call back with recursive func but it doesn’t look smooth:

function MovePanel() {
    sidePanel.animate({
        "marginTop": newCurrTop
    }, moveSpeed, function () {
        MovePanel();
    });
}

Is it possible to slow down an JQuery animation?

If not what are the alternatives?

Thanks.


回答1:


The animate method takes a 3rd param called "easing"; learn about it here:

http://api.jquery.com/animate/




回答2:


You might want to check this out: http://www.learningjquery.com/2009/02/quick-tip-add-easing-to-your-animations

Easing can really bring life to an effect. Easing controls how an animation progresses over time by manipulating its acceleration.



来源:https://stackoverflow.com/questions/2382002/jquery-animation-is-it-possible-to-change-speed-during-the-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!