First, the uniform motion of javascript
About the object JavaScript Uniform Motion Essentials Analysis:
1. When the object is moving, we need to turn on the timer.
2. When the timer is turned on, we remember to turn off the timer when it is stopped, and notice that when it starts loading, we should also turn off the timer and avoid repeated loading, resulting in accelerated motion.
3. And the speed is initialized to 0
Implementation method:
Determine if the object's offset is less than the target value (judging the speed of the motion)
Less than can continue motion greater than right motion
2. Tell me where to stop first.
Judging condition: The physical offset is less than 7 when the value of the speed cannot be exceeded
Just get it aligned.
<!doctype html>
Second, JavaScript variable motion
Key points of Analysis:
1. How do I change the speed of movement? The difference between the target value and the deviation value (obj.offsetleft) is removed with a fixed value because the deviation value (obj.offsetleft) changes over time to achieve a variable speed.
2. Judging speed greater than 0 upward rounding less than 0 down rounding
<!doctype html>
Third, the elastic motion of JavaScript
1. Start a deceleration exercise
2. Add a friction motion to the deceleration movement
To do a speed-slowing acceleration of the acceleration ispeed + = (itarget-obj.offsetleft)/5;//control speed of the deceleration of friction ispeed *= 0.7;//left move distance = Ispee D
<!doctype html>
A tutorial on JavaScript's motion