日期:2014-05-16  浏览次数:20370 次

如何实现按显示器对角线运动的 浮动图片
比如运动按直线由左上角到右下角

------解决方案--------------------
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title> 对角线运动 </title> <script>
var current_x=0;
function a(){
var x=document.body.clientWidth;
var y=document.body.clientHeight;
b(x,y);
}
function b(x,y){
if(current_x <(x-100)){
current_x=parseInt(current_x)+1;
document.all.div1.style.left=current_x;
document.all.div1.style.top=parseInt((y/x)*current_x);
window.setTimeout( "b( "+x+ ", "+y+ ") ",10);
}
}
</script>
</head>
<body onload= "a() ">
<div id=div1 style= "background-color:#cccccc;position:absolute;top=0px;left=0px;width:100px;height:100px "> 对角线运动 </div>
</body>
</html>