简单的 Javascript 数学函数

发布于 2024-12-09 04:04:53 字数 283 浏览 0 评论 0原文

这应该很容易,但由于某种原因我一直在错误地处理它。

我需要逐步增加基数,从一到无穷大。

我有一个数字,以毫秒为单位表示动画的持续时间,从 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别忘他 2024-12-16 04:04:53
  animationDuration = difference * increment ??
  animationDuration = difference * increment ??
旧瑾黎汐 2024-12-16 04:04:53

解决方案:

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;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文