本帖最后由 Gaara33 于 2014-6-18 21:26 编辑
<!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>
<style type="text/css">
#bodyid{
border:#3F0 1px solid;
height:600px;
width:800px;
}
</style>
<script type="text/javascript">
window.onload = function()
{
document.body.onmousemove = function()
{
var adNode = document.getElementById("ad");
//var adNode = document.getElementsByTagName("div")[0];
//alert(adNode.nodeName);
adNode.style.left = event.x;
adNode.style.top = event.y;
}
}
function closead()
{
var adNode = document.getElementById("ad");
ad.style.display = "none";
}
</script>
</head>
<body>
<div id="ad" style="position:absolute; left:0; top:0">
<a target="_blank"><img src="cc.jpg" height="80px" width="100px" /></a>
</div>
<div id="bodyid">
body区域
</div>
</body>
</html>
在看毕老师的视频时,这是个图片区域会随鼠标移动的小例子,但是我这样写后,没有效果,就是不会移动,后来搜了一下,发现要在event.x和event.y后面+"px",然后就运行正常了,虽然解决了问题,但是为什么呀?为什么毕老师做演示的时候就没问题? |
|