A summary of the knowledge points of JS movement (with examples of elastic motion) _javascript Tips

Source: Internet
Author: User
Tags abs

This paper summarizes the knowledge points of JS movement. Share to everyone for your reference, specific as follows:

1. Multi-Object Motion framework nothing can be shared.

2.document.title output frequency is not too high

3. When writing JS, try to avoid writing decimal, because the internal computer is simulated, not the actual storage

such as: 0.07*100 in the JS operation is not for 7

var a=3;
var b=3.00000000000000000001;
alert (A=B);

The result of the output is true

4. Write program thinking before thinking general, and then thinking special, write program is, first exclude special, and then write general

if (special 1)
{}
else if (special 2)
{}
else
{
 General
}

5. Arrays can be used for either a for loop or a for ... In loop, because the for loop is more controllable, so the For loop is better

Object (JSON) can only be used for ... In loop

6. *{margin:0;padding:0 in CSS; This is not a good write performance.

7. Layout conversion, first set the Left,top value for each element, all set up to give each element position set absolute and margin clear zero

8.ie7 in the use of UL sports will card, this time can use Div to try

9. Consider the friction factor ispeed*0.95 (the size of the decimal number depends on the size of the friction)

10. Acceleration, the farther the acceleration from the target, the nearer the target, the smaller (itarget-obj.offsetleft)/50

11. The combination of acceleration and friction is 5 and 0.7, i.e. ispeed+= (itarget-obj.offsetleft)/5; ispeed*=0.7;

12. When the program goes wrong, think about why this problem occurs

13. The elastic movement cannot be used when the style cannot cross the boundary

14. Elastic Motion Stop Condition: the distance too near speed too small

15. Analysis to onlookers analysis, because the style will automatically ignore decimals, so in order not to let the missing decimal add up, you can set a variable to store, and then assign to the style. obj.style.left=left+ "px";

Attached: JavaScript Elastic motion Examples

Motion principle: Acceleration Movement + deceleration movement + friction movement;

The code is as follows:

<!doctype html>  

More about JavaScript motion effects to view the site topics: "JavaScript movement effect and Skills summary"

I hope this article will help you with JavaScript programming.

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.