A tutorial on JavaScript's motion

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.