2021 年的现代答案。您不必为此使用 jQuery。但我假设你愿意。您可以将流行的 npm 库(如 popmotion(每周下载 60 万次))与 jQuery 结合使用,如下所示:
// poo.el.animate({top: footerTop - horsePooHeight})
// your imports may vary - I'm using Angular, popmotion focuses more on Vue and React
import { cubicBezier } from 'popmotion'
declare const popmotion: any
const {tween, easing} = popmotion
const fling = cubicBezier(0, .42, 0, 1)
tween({from: 100, to: 200, duration: 400, ease: fling}).start((v) => $(el).css('top', v))
tween({from: 100, to: 300, duration: 400, ease: easing.linear}).start((v) => $(el).css('left', v))
其中 el 是一个 jQuery 元素。
好消息。它在缓和、允许曲线方面拥有更大的力量。坏消息是它有点复杂,但如果你能理解上面的代码,你会没事的。
PS 我不是说 popmotion 应该与 jQuery 一起使用。我只是说可以。
PPS 永远不要忘记耶稣爱你 :D
PPPS jQuery 适用于更简单的动画,但对此类问题缺乏兴趣以及 jQuery 动画库缺乏更新证明,jQuery 本身对于更复杂的动画来说已经死了。