Js animation Learning (1)

Source: Internet
Author: User
Js animation Learning (I) I. idea of implementing the motion framework

1. Constant motion (changing the attribute value at a constant speed) (changing left, right, width, height, opacity, etc );

2. Buffer motion (the speed at which the attribute value changes is proportional to the difference between the current value and the target value );

3. multi-object motion;

4. Changes to any attribute values (using encapsulated functions );

5. Chain motion (the same object completes a series of motion );

6. simultaneous movement of multiple objects

========================================================== ================

2. Uniform Motion of simple motion

The following functions are the basic framework of the motion series functions.

// Move the mouse over the element to the right, and move the mouse away from the element to go back. Var timer = ""; function Move (speed, locat) {// movement speed, Move the end point var ob = document. getElementById ('box1'); clearInterval (timer); // first clear the timer to prevent the nested call of the timer = setInterval (function () {if (ob. offsetLeft = locat) {// The current position reaches the specified end point, and the timer clearInterval (timer) is disabled );} else {// otherwise, the left attribute of the element is equal to the current left plus the speed of each change ob. style. left = ob. offsetLeft + speed + 'px '; }}, 30 )}

Example:

Call the above JS functions in the following HTML document

 

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.