2009-07-27 167 views

回答

0

我最近有類似的挑戰,並制定了以下代碼。該代碼適用於IE瀏覽器,但Chrome瀏覽器中的freeze header的寬度有問題。

不管怎樣,希望它幫助。

<script type="text/javascript"> 
$(document).ready(function(){ 
    // Replace 'NameOfList' with the name of the SharePoint list 
    var $header = $("table[summary^='NameOfList']:first > tbody > tr.ms-viewheadertr"); 
    var headertop = $header.offset().top; 

    // Replace 'NameOfColumn' with the name of the column that you would like to freeze 
    var $fzCol= $("tr.ms-viewheadertr th:contains('NameOfColumn')"); 

    // IE has iFrame, Chrome doesn't have, so the 'n-th' count of the column is different in IE than in Chrome 
    if($fzCol.siblings().eq(0).children().eq(0).prop("tagName") == "IFRAME"){ var shift = 0} else { var shift = 1}; 
    var nfzCol=$fzCol.index()+shift; 

    var $mcol=$("table[summary^='NameOfList'] > tbody > tr:not(.ms-viewheadertr) > td:nth-child("+nfzCol+")"); 
    var colleft=$mcol.eq(0).offset().left; 

    $(window).scroll(function(){ 
    var windowtop = $('body').scrollTop(); 
    if(windowtop > headertop){ 
     $header.css({"position":"absolute", "top":windowtop}); 
    } else { 
     $header.css({"position":"static", "top":"0px"}); 
    } 

    var windowleft = $('body').scrollLeft(); 
    if (windowleft > colleft){ 
     $mcol.css({"position":"relative", "left": windowleft-colleft}); 
    } else { 
     $mcol.css({"position":"static", "left":"0px"}); 
    } 
    }); 
} 

相關問題