I
I
Isotheos2014-11-29 22:51:28
JavaScript
Isotheos, 2014-11-29 22:51:28

How to set a Bezier curve to control the speed of step animation?

Good day.
The subject of the problem I encountered is indicated in the title, so I'll just try to describe it in more detail using an example.
Let's say there is a script that moves an element on the page and calls itself until the element has reached the right place. Accordingly, the speed turns out to be linear, in each function call the same value is added to the position of the element, equal to:
(end point - start point) / number of steps
I'm more interested in the ability to make the speed curvilinear, according to a given Bezier curve. Do you have any clues in which direction to dig?
And yes, the original problem is somewhat larger and more complex than the example shown, but the catch is precisely in the use of non-constant speed.
The simplest function code example (yes, I know about jQuery's .animate() function, see the previous paragraph :) )

function animate_rect(i,step) {
  var rect = $('#rect');
  var pos = rect.position();
  rect.css({top:pos.top + ((200 - pos.top) / (step - i))});
  i++;
  if (i < step) setTimeout(function() {animate_rect(i,step)},10);
}
animate_rect(0,100);

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Isotheos, 2014-11-30
@Isotheos

Thank you all, knowing what to look for, I found the necessary information - learn.javascript.ru/js-animation

A
Armenian Radio, 2014-11-29
@gbg

You will certainly be interested in the Lagrange interpolation polynomial.
This thing allows you to build a smooth curve connecting these points using a given set (coordinate where we are now, speed). You will only have to calculate the speed at each point according to the resulting formula.

N
neolink, 2014-11-29
@neolink

from the text it is not clear why not animate?
here on the topic - easing functions easings.net/ru
generator of easing functions based on a bezier curve: https://github.com/rdallasgray/bez

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question