Today I have learned animation in javascript
Animation in javascript:
JavaScript animations can handle things that CSS can’t.
For instance, moving along a complex path, with a timing function different from Bezier curves, or an animation on a canvas.
An animation can be implemented as a sequence of frames – usually small changes to HTML/CSS properties.
For instance, changing style.left from 0px to 100px moves the element. And if we increase it in setInterval, changing by 2px with a tiny delay, like 50 times per second, then it looks smooth. That’s the same principle as in the cinema: 24 frames per second is enough to make it look smooth.
Let’s imagine we have several animations running simultaneously.
If we run them separately, then even though each one has setInterval(..., 20), then the browser would have to repaint much more often than every 20ms.
That’s because they have different starting time, so “every 20ms” differs between different animations. The intervals are not aligned. So we’ll have several independent runs within 20ms.
In other words, this:
.png)
Comments
Post a Comment