Wesley
Wesley

Reputation: 5621

Simple Javascript Math Function

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.

Upvotes: 2

Views: 290

Answers (2)

Wesley
Wesley

Reputation: 5621

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;

Upvotes: 0

Charles Bretana
Charles Bretana

Reputation: 146449

  animationDuration = difference * increment ??

Upvotes: 2

Related Questions