In the project of making an unmanned convenience applet, one day the product said that it would learn from a certain manufacturer's product and add a parabolic ball animation to the shopping cart. This article mainly gives you a detailed analysis of the JS parabolic animation production process and the sharing of related code examples. Friends who are interested can refer to it.
Let me show you the renderings first
Analysis
This kind of non-fixed start Of course, position animation cannot use GIF images, so it can only be implemented using native code
So what tools do we have to implement animation?
The applet provides the JS API createAnimation to create animations
CSS animation
Now that the tool is available, let’s take a look What is a parabola.
Here we only discuss the horizontal parabola. From the mathematical principle, the horizontal parabola is [movement with constant horizontal speed and vertical acceleration]. The conversion to the code level is in the animation effect timingFunction. The horizontal animation uses linear and the vertical animation uses ease-in
So we need to decompose this parabolic animation into two animations that are performed simultaneously but with different animation effects.
Implementation
Implementation of small program
JS:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
HTML:
1 2 3 |
|
As far as I know, the animation implemented with transform: transform() will have better performance than top & left, but try I found that the ideal interaction effect cannot be achieved, and I look forward to continuing to study it
H5 implementation
1 |
|
Related recommendations:
The above is the detailed content of JS parabolic animation operation example sharing. For more information, please follow other related articles on the PHP Chinese website!