functionmoveelement (elementid,final_x,final_y,interval) {if(!document.getelementbyid)return false; if(!document.getelementbyid (ElementID))return false; varelem=document.getElementById (ElementID); varxpos=parseint (Elem.style.left); varypos=parseint (elem.style.top); if(xpos==final_x&&ypos==final_y) { return true;} if(xpos<final_x) {xpos++;} if(xpos>final_x) {xpos--;} if(ypos<final_y) {ypos++;} if(ypos>final_y) {ypos--;} Elem.style.left=xpos+ "px"; Elem.style.top=ypos+ "px"; varrepeat= "Moveelement ('" +elementid+ "'," +final_x+ "," +final_y+ "," +interval+ ")"; Movement=setTimeout (Repeat,interval); } addloadevent (movemessage);
The Moveelement function is used to move a document with an ID element attribute as long as the element ID, the final x-coordinate, the final y-coordinate, and the time interval are given. You can call this function.
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); }addloadevent (positionmessage);
The Positionmessage function, which sets the document position function with the ID element attribute, can be animated with the Moveelement function.
moveelement function and Positionmessage function