JS's Perfect motion frame

Source: Internet
Author: User

function GetStyle (obj, name) {if (Obj.currentstyle) {return obj.currentstyle[name];} else{return getComputedStyle (obj, FALSE) [name];}} Note: In a multi-object motion frame, everything is not public! Otherwise the problem, the BUG, and the necessary variables are added to the properties of the object on the line. That is: The property is bound to the moving object: speed, other attribute values (such as transparency, and so on) function startmove (obj, JSON, fnend)//Perfect motion frame//For JSON, such as: Startmove (Odiv, {width:400,   height:400}) {clearinterval (Obj.timer); Obj.timer=setinterval (function () {var bstop=true; The key//hypothesis: All values have been reached for the (Var attr in JSON)//With a loop, the original set of things wrapped in the inside, each time the timer executes, will cycle, the number of cycles depends on what is written in the JSON {var cur=0;if (attr== ' opacity ') {Cur=math.round (parsefloat (GetStyle (obj, attr)) *100);//Because here, there will be a problem, fractional}else{cur=parseint (GetStyle (obj, attr));} var speed= (json[attr]-cur)/6;speed=speed>0? Math.ceil: Math.floor (Speed), if (Cur!=json[attr]) bstop=false;if (attr== ' opacity ') {obj.style.filter= ' alpha ( Opacity: ' + (cur+speed) + ') '; obj.style.opacity= (cur+speed)/100;} else{obj.style[attr]=cur+speed+ ' px ';}} if (bstop)//If all values are reached, close timer {clearinterval (obj.timer); if (fnend) Fnend ();}}, 30); }



Description

obj---------------> Moving nodes

JSON------------> What to do with: {width:300,height:200} 300, 200 as the target point

Fu---------------> action after the end of the exercise such as: a pop-up window after the end of the campaign



This JS perfect motion frame is CSS2 ~

In CSS3 there is a framework beyond the perfect frame of motion-the frame in CSS3 and CSS2.

JS's Perfect motion frame

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.