JS Animation moving from one position to another general

Source: Internet
Author: User

<! DOCTYPE html>
Function positionmessage () {if (!document.getelementbyid)  return false;if (! document.getElementById ("message"))  return false;var elem = document.getelementbyid (" Message ");elem.style.position = " absolute ";elem.style.left = " 50px "; elem.style.top =" 100px "; Moveelement (" message ", 200,100,10);} Function moveelement (Elementid,final_x,final_y,interval) {if (!document.getelementbyid)  return  False;if (!document.getelementbyid (elementid))  return false;var elem =  document.getElementById (ElementID); Var xpos = parseint (Elem.style.left);  //parseint (string The numeric information inside the string is extracted, because there are a lot of arithmetic comparisons to be done later. Var ypos = parseint (Elem.style.top);   //parsefloat (string) extracts a numeric value (that is, a floating-point number) with decimals. if (xpos == final_x && ypos == final_y) {return true;} if (xpos < final_x) { xpos++;}        //if Xpos is less than the end of the LefT, give it add 1.if (xpos > final_x) { xpos--;}        //if Xpos is greater than the end of the left, give it minus 1.if (ypos < final_y) { ypos++;}        //if Ypos is smaller than the left end of the endpoint, add 1.if (ypos > final_y) { ypos--;}        //if Ypos is greater than the end of the left, give it 1.elem.style.left = xpos +  "px";elem.style.top = ypos +  "px";//var  repeat = function ()  { Moveelement (elementid, final_x,final_y,interval)} varrepeat =  "MoveElement ('"  +  elementid +  "',"  + final_x +  ","  + final_y +  ","  +  interval +  ")"; Movement = settimeout (Repeat,interval);//cleartimeout (movement);   In the interval of waiting time, can cancel this "jump" behavior}addloadevent (positionmessage);

JS animation moves from one position to another in a common position

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.