浮动表头

http://www.51ajax.com/blog/?p=172

这个的扩充版

可实现双重表头

 

 

//表头浮动
function onScroll(){
 var scrollRows=sorttable.scrollRows;
 
 if(scrollRows.length>0){
        for(var i = 0; i < scrollRows.length; i++){   
            var arr = scrollRows[i];
   var pos=arr[1];
   //如果表格可见
   if(pos.width>0 && pos.height>0){    
             var top = (document.documentElement && document.documentElement.scrollTop)?document.documentElement.scrollTop : document.body.scrollTop;
             if(i==1)top+=17;
    var maxBottom = arr[1].top+arr[2].height-2*arr[1].height ;
    if(top<arr[1].top){
     arr[0].style.position = "relative";
     arr[0].style.top = "0px";     
    }
    else if(top >arr[1].top && top < maxBottom){
     arr[0].style.position = "absolute"; 
     arr[0].style.top = top+"px";      
             } 
   }
        }
    }
}

 

你可能感兴趣的:(Blog)