Set the initial position and end point in the second function positionmessage, the new HTML file is, the element ID is a message.
function Addloadevent (func) {
var oldonload = window.onload;
if (typeof window.onload! = ' function ') {
Window.onload=func;
}else{
Window.onload = function () {
Oldonload ();
Func ();
}
}
}
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);
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);
var ypos=parseint (elem.style.top);
if (xpos = = final_x && ypos==final_y) {
return false;
}
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";
var repeat = "moveelement ('" +elementid+ "'," +final_x+ "," +final_y+ "," +interval+ ")";
Movement = SetTimeout (Repeat,interval);
}
JavaScript for simple animation functions