简单的 Javascript 数学函数
这应该很容易,但由于某种原因我一直在错误地处理它。
我需要逐步增加基数,从一到无穷大。
我有一个数字,以毫秒为单位表示动画的持续时间,从 750 开始。我有另一个数字,表示我们要跳过的元素数量。
var animationDuration = 750;
var difference = Math.abs(currentPanelIndex - target); //somewhere from 1 - X
我需要为每个差异数字逐渐增加动画持续时间。
This should be easy, but for some reason I keep approaching it wrong.
I need to incrementally increase a base number, on a one to infinity scale.
I have a number representing in milliseconds the duration of an animation, starting at 750. I have another number, representing the number of elements we are skipping.
var animationDuration = 750;
var difference = Math.abs(currentPanelIndex - target); //somewhere from 1 - X
I need to increase animationDuration incrementally for each number in difference.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案:
Math.abs(currentPanelIndex - target) 给出了我们的差异
(animationDuration / 10) 给出的增量是标准持续时间的 1/10
所以:
var currentDuration = Math.abs(currentPanelIndex - 目标) * (animationDuration / 10) +animationDuration;
Solution:
Math.abs(currentPanelIndex - target) gives us our difference
(animationDuration / 10) gives us an increment that is 1/10 of the standard duration
So:
var currentDuration = Math.abs(currentPanelIndex - target) * (animationDuration / 10) + animationDuration;