随滚动条滚动的两侧的层

最近工作中遇到了随滚动条滚动的层,在网上查了下有很多关于这方面的内容,感觉有点麻烦,还是自己总结下的好,既简单又实用。代码如下:

 

<script type="text/javascript">
function FloatTop()
{
  var startX1 =document.body.scrollLeft+document.body.offsetWidth-115 ,startY1 = document.documentElement.scrollTop+100;
  var startX2 = 0,startY2 = document.documentElement.scrollTop+100;
  var ns = (navigator.appName.indexOf("Microsoft") != -1);
  var d = document;
  function ml(id,startX,startY)
  {
    var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
    if(d.layers)el.style=el;
    el.sP=function(x,y){this.style.left=x+"px";this.style.top=y+"px";};
    el.x = startX;
    el.y = startY;
    return el;
  }
  window.stayTopLeft=function()
  {
   // var pY = ns ? document.documentElement.scrollTop : document.body.scrollTop;
   var pY=document.documentElement.scrollTop;
    ftlObj.y += (pY + startY1 - ftlObj.y)/8;
    ftlObj1.y += (pY + startY2 - ftlObj1.y)/8;
    ftlObj.sP(document.body.scrollLeft+document.body.offsetWidth-115, ftlObj.y);
    ftlObj1.sP(ftlObj1.x, ftlObj1.y);
    setTimeout("stayTopLeft()", 10);
  }
  ftlObj = ml("rightaa",0,document.documentElement.scrollTop+100);
  ftlObj1 = ml("leftaa",5,document.documentElement.scrollTop+100);
  stayTopLeft();
}
FloatTop();

function closeDiv(objID)
{
 document.getElementById(objID).style.display="none";
 }
</script>

<div class="qq_box left" id="leftaa" name="leftaa" style="position:absolute; left:2px; top:107px;">ddd</div>

<div class="qq_box1 right" id="rightaa" name="rightaa" style="position:absolute; right:2px; top:107px;">ddd</div>

<a title="关闭窗口" href="javascript:void(0);" onclick="closeDiv('leftaa');">×</a>//关闭左侧窗口

<a title="关闭窗口" href="javascript:void(0);" onclick="closeDiv('rightaa');">×</a>//关闭右侧窗口

你可能感兴趣的:(JavaScript,工作,qq,Microsoft)