如何减慢和停止当前的jQuery动画? [英] How to slow down and stop current jQuery animation?

查看:82
本文介绍了如何减慢和停止当前的jQuery动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jQuery问题。
我有动画.block向右移动5000px。

jQuery question. I have animated .block moving to the right for 5000px.

$(".block").animate({"left": "+=5000px"}, 2000, 'linear');

我需要的是在点击后慢慢停止这个动画:

What I need is to slowly stop this animation after the click:

('#clickme').click(function() {
 // ... stop $(".block") animation, not immediately, but with some easing
});

jQuery可以实现吗?任何建议将不胜感激。

Is this possible with jQuery? Any suggestions will be appreciated.

推荐答案

我将通过在用户点击停止触发器时停止动画来解决这个问题,然后开始一个新的动画,给人一种缓和停止的幻觉。这是一个例子: http://jsfiddle.net/brianflanagan/BsQvh/ 诀窍是调整设置第二部动画让事情顺利进行。您需要将持续时间和距离结合起来,以便与原始动画的速度融合。

I'd tackle this by stopping the animation when the user clicks the stop trigger, then start a new animation that gives the illusion of an eased stop. Here's an example: http://jsfiddle.net/brianflanagan/BsQvh/ The trick is tweaking the settings of the second animation so things work smoothly. You'll want to marry the duration and the distance so it blends with the original animation's pace.

这篇关于如何减慢和停止当前的jQuery动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆