Home  >  Article  >  Web Front-end  >  Summary of the key points of native js movement methods

Summary of the key points of native js movement methods

一个新手
一个新手Original
2017-10-09 10:01:131199browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn