Home > Article > Web Front-end > Summary of the key points of native js movement methods
Main method: Use of timer setInterval(function(){},30);
In order to avoid errors when the speed is about to stop at the last moment, you can use the following method:
if(iSpeed<1)//速度足够小的时候,让速度直接为0,避免速度的波动{ iSpeed = 0; }
Use of absolute values (mainly used in elastic motion and other situations where the speed is positive and negative):
Math.abs(2.5)// 2
Combination of elastic motion and friction:
iSpeed+=(iTarget-obj.offsetLeft)/5; iSpeed*=0.7;
Simulated friction:
iSpeed*=0.95;//小数速度会越来越小
Deceleration motion:
iSpeed--;
Acceleration motion:
iSpeed++;
Elastic motion:
iSpeed+=(300-op.offsetLeft)/50;
Collision motion:
iSpeed *= -1;
The above is the detailed content of Summary of the key points of native js movement methods. For more information, please follow other related articles on the PHP Chinese website!