具体代码如下:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
#demo1{
width:300px;
height:200px;
border:3px solid #F00;
}
</style>
<script>
function ceh1(element)
{
element.style.color="#0f0";
element.style.backgroundColor="#a4c639";
movement=setTimeout("ceh3()",1000);
}
function ceh2(element)
{
element.style.color="";
element.style.backgroundColor="";
}
function ceh3()
{
element=document.getElementById("demo1");
xpox=parseInt(element.style.left);
ypox=parseInt(element.style.top);
if(xpox==700 && ypox==300)
return true;
if(xpox<700)xpox++;
else xpox--;
if(ypox<300)ypox++;
else ypox--;
element.style.left=xpox+"px";
element.style.top=ypox+"px";
movement=setTimeout("ceh3()",10);
}
</script>
</head>
<body>
<div id="demo1" onMouseOver="ceh1(this)" onMouseOut="ceh2(this)" style="position:absolute; top:100px; left:100px;">
</div>
</body>
</html>