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

求一脚本动画
本帖最后由 z578410840 于 2012-12-31 22:41:13 编辑
点击按钮,有个图片从按钮位置飞向右下角

------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function init(){
var button=document.getElementById("test");
button.onclick=show;
}
function show(){
this.onclick=null;
var information={
position:"absolute",
left:"0px",
top:"0px",
width:"200px",
height:"200px"
}
var img=document.createElement("img");
img.src="1.gif";
for(var i in information){
img.style[i]=information[i];
}
document.body.appendChild(img);
var screenX=document.documentElement.clientWidth
------解决方案--------------------
document.body.clientWidth;
var screenY=document.documentElement.clientHeight
------解决方案--------------------
document.body.clientHeight;
var d=parseInt(screenX/screenY)+1;
move(img,this,d,screenY-200);
}
function move(img,button,d,y){
img.style.left=parseInt(img.style.left)+d+"px";
img.style.top=parseInt(img.style.top)+1+"px";
var p=window.setTimeout(function(){move(img,button,d,y)},10);
if(parseInt(img.style.top)>=y){
window.clearTimeout(p);
img.parentNode.removeChild(img);
button.onclick=show;
}
}
window.onload=init;
</script>
</head>

<body>
<input type="button" value="show" id="test" />
</body>
</html>
大体这样试试  要正好到右下角貌似的仔细计算一下图片和屏幕的长宽才可以