is it posible, to animate css rotate
as linear transition (take start and end points of transition and use them like a keyframes where points go straight forward to their final position)?
for example:
by default rotation from 1
to 2
would go by circular way (blue one), but i want it to go from "point to point" (yellow one), but also keep it smooth (not make something like steps(1)
)
3
Answers
You can use keyframes
Here you can learn more about keyframes : link
What you’re proposing to do is not possible with only rotation.
The path that needs to be traversed in a circle is always equidistant from the center point, or origin.
The path that needs to be traversed in your question involves scaling or translating the object being rotated.
Edit: More detailed explanation: If you measure the distance to a point on the circle from the origin, it is further than the distance to the midpoint on the line from the origin.
The scale needs to be equal to 1 at each point. The scale needs to be smaller at a keyframe exactly in between one point and the next. Or a similar solution if you are translating it instead.
The result is that you need to add a scaling transition between each rotate you already have and the scale back to 1 at your existing ones.
Edit #2: This is by no means perfect, but this is the basic idea. I would ideally write something like this in SCSS due to the math involved, but there’s nothing like the basics.
The red circle is moving along the outer path of an invisible circle between 12 points like a clock.
For each half hour, I translate the red circle closer to the origin, then back out on the hour. This is what makes it appear as if it is taking a straight line from one point to the next.
Rotating the circle at normal speed and varying the distance to the center at just the right ratio will give you what you want.
Finding the right ratio depends on how many target points/keyframes rest along the circles edge. If you have half as many points as the clock example with 12, the midpoint of each line segment will be closer to the center and thus more translation is necessary in each frame. If you have more than 12, the midpoints will be further away than in the example.
To get the line to rotate with its end point following a straight line rather than round the arc of the circle you can place a solid color over the part you do not want displayed.
This snippet does this by using the before pseudo element of a div as the line and the after pseudo element (rotated about its bottom right hand corner) to hide the end of the line.
Using CSS rotation transform on the line with linear timing means the movement is linear.
This snippet adds the outer circle and the yellow line shows the cut off.