想了解Animate函数(计算和步进) [英] Would like to understand the Animate function (calculation and stepping)

查看:74
本文介绍了想了解Animate函数(计算和步进)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道jQuery .animate()函数如何工作? -计算和步进(跳了多少)

I would like to know how does the jQuery .animate() function work? - calculation and stepping (how much it jumps)

推荐答案

动画开始时,将使用时间戳记.然后,每触发一个步骤(取决于浏览器和正在进行的操作),就会计算出自动画开始以来经过了多少时间,并由此计算出进度.

When the animation starts, a timestamp is taken. Then everytime a step triggers (depends on browser and how much stuff is going on), it is calculated how much time has passed since the animation started and the progress is calculated from that.

例如,动画从1322338364714​​开始,该动画应该持续5000ms.触发步骤后,将按如下方式计算进度:

For example, animation started at 1322338364714, and the animation is supposed to last 5000ms. Once a step is triggered the progress is calculated like so:

  1. 获取当前时间,例如1322338366714.
  2. 规范化= 1322338366714-1322338364714​​ = 2000
  3. 进度为2000/5000 = 0.4 = 40%.因此,从0像素到100像素进行动画处理的div的高度为40像素.

这篇关于想了解Animate函数(计算和步进)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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