Motion function move all kinds of motion can do

Source: Internet
Author: User

What I'm talking about here is the kind of uniform motion, mainly by changing the left and top values of a box die to achieve motion, or, changing the properties of the shape itself, to move:

function GetStyle (obj,name) {return Obj.currentstyle?obj.currentstyle[name]:getcomputedstyle (obj,false) [name];}; function Move (obj,json,options) {options=options| | {};options.time=options.time| | 700;var Start={};var Dis={};for (var name in JSON) {if (name== ' opacity ') {start[name]=parsefloat (GetStyle (Obj,name));} Else{start[name]=parseint (GetStyle (obj,name)); Dis[name]=json[name]-start[name];}; var count=math.round (OPTIONS.TIME/30), Var n=0;clearinterval (Obj.timer), Obj.timer=setinterval (function () {n++;for ( var name in json) {var cur=start[name]+dis[name]*n/count;if (name== ' opacity ') {Obj.style.opacity=cur;obj.style.filter = ' Alpha (opacity: ' +cur*100+ ') ';} else{obj.style[name]=cur+ ' px ';}}},30);}

  

GetStyle This function is to get the style properties, the previous piece has been said;

Here is the formula for moving the transport:

Start distance + (end distance-start distance) * movement several times/altogether can exercise how many times;

Starting distance here with start, the end distance with a JSON data, Json[name], is the end distance, n represents the movement of several times, the count represents, 30 milliseconds walk once, a specified time to walk the total number of distance.


Motion function move all kinds of motion can do

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.