Home > Web Front-end > JS Tutorial > body text

Summary of the key points of native js movement methods

一个新手
Release: 2017-10-09 10:01:13
Original
1199 people have browsed it

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;
}
Copy after login

Use of absolute values ​​(mainly used in elastic motion and other situations where the speed is positive and negative):

Math.abs(2.5)// 2
Copy after login

Combination of elastic motion and friction:

iSpeed+=(iTarget-obj.offsetLeft)/5;
iSpeed*=0.7;
Copy after login

Simulated friction:

iSpeed*=0.95;//小数速度会越来越小
Copy after login

Deceleration motion:

iSpeed--;
Copy after login

Acceleration motion:

iSpeed++;
Copy after login

Elastic motion:

iSpeed+=(300-op.offsetLeft)/50;
Copy after login

Collision motion:

iSpeed *= -1;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template