<! 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