<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>文哥讨厌IE</title>
</head>
<body>
<div id="over" onmousedown="down(this,event)" style="width:100pxheight:30pxbackground:redposition:absoluteleft:20pxtop:500px" onmousemove="move(this,event)" onmouseup="seup(this,event)">
</div>
<script type="text/javascript">
var posX,posY
var downX,downY
var mark=false
function down(obj,event)
{
obj.style.cursor="move"
posX=obj.style.left
posY=obj.style.top
downX=event.clientX
downY=event.clientY
mark=true
///alert(posX)
///alert(posY)
}
function move(obj,event)
{
var moveX=event.clientX
var moveY=event.clientY
if (mark) {
obj.style.left=parseInt(moveX) + parseInt(posX) - parseInt(downX) + "px"
obj.style.top=parseInt(moveY) + parseInt(posY) - parseInt(downY)+ "px"
}
}
function seup(obj,event)
{
if (mark) {
var moveX=event.clientX
var moveY=event.clientY
obj.style.left=parseInt(moveX) + parseInt(posX) - parseInt(downX)+ "px"
obj.style.top=parseInt(moveY) + parseInt(posY) - parseInt(downY)+ "px"
downX=moveX
downY=moveY
}
obj.style.cursor="default"
mark = false
}
</script>
</body>
</html>
不考虑IE6的话就比较简单,判断一下是否到底部,到了之后将这个div的position设置为fixed就好了top值是固定的 但是如果要考虑IE6的话就麻烦一点,因为IE6不支持fixed这个属性你只能通过absolute来处理而此时top值是要不停地改变的,而且在IE6中这个div在滚动时会不停晃动,解决方法是有的但是代价过高,看你的取舍