没有加上"px",加上就可以了。
<!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">
document.onmousemove=function(){
var x=window.event.clientX;//获取鼠标的横坐标
var y=window.event.clientY;//获取鼠标的纵坐标
var dyf=document.getElementById("d1");
if(!dyf){ //判断图片是否已经加载完成
return;
}
dyf.style.left=x+"px";
dyf.style.top=y+"px";
}
</script>
</head>
<body>
<div id="d1" style="position:absolute"><img src="kt_000001.jpg" /><br />我要飞</div>
</body>
</html>
|