<!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=gb2312" />
<title>JS实现上下浮动代码</title>
</head>
<body>
<script language="javascript" type="text/javascript">
var w3c = (document.getElementById) ? true : false;
var agt = navigator.userAgent.toLowerCase();
var ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1) && (agt.indexOf("omniweb") == -1));
var mymovey = new Number();
function IeTrueBody(){
    return (document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body;
}
function GetScrollTop(){
    return ie ? IeTrueBody().scrollTop : window.pageYOffset;
}
function heartBeat(){
    diffY=GetScrollTop(); 
    mymovey += Math.floor((diffY-document.getElementById('backi').style.top.replace("px","")+50)*0.1);
    document.getElementById('backi').style.top = mymovey+"px";

window.setInterval("heartBeat()",1);
</script>
<div style="height:1500px;width:1000px;background:#FFFFFF;"></div>
<div id="backi" style="z-index:1;width:150px;height:350px;position:absolute;right:20px;float:right;margin:0px;border:1px solid #0000FF;">
Hello
</div>
</body>
</html>