求助:Div(onmousemove)跟随鼠标,scrollTop之后按鼠标滑轮div与鼠标不一致
代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
document.onmousemove=function (ev)
{
var oEvent=ev||event;
var oDiv=document.getElementById('div1');
var scrollTop=document.documentElement.scrollTop|| document.body.scrollTop;
oDiv.style.left=oEvent.clientX+scrollTop+'px';
oDiv.style.top=oEvent.clientY+scrollTop+'px';
};
</script>
<style>
#div1{ width:200px; height:200px; background:red; position: absolute;}
</style>
</head>
<body style="height:2000px;">
<div id="div1"></div>
</body>
</html>
[此贴子已经被作者于2016-7-21 17:31编辑过]