1

URL にハッシュが含まれている場合、テーブルの最初の行をカバーする tablesorter の stickyHeaders ウィジェットに問題があります。

たとえば、living.php?tab=1#sacramento1

ページには正しいタブが表示され、正しい行にジャンプしますが、ヘッダーが行の上に表示されます。

これを回避するために、URL にハッシュがある場合は stickyHeader ウィジェットを無効にしています。

これが私がやっていることです:

<script type="text/javascript">$(document).ready(function() 
{ 
  //CHECK for hash. don't want sticky headers with hash
  if (window.location.hash) {
    var workingID = window.location.hash;
    tid=workingID.substr(1,workingID.length);
    document.getElementById(tid).setAttribute("class", "showRow");
    // extend the default setting to always include the zebra widget. 
    $.tablesorter.defaults.widgets = ['zebra'];
  } else {
    // extend the default setting to always include the zebra widget and the sticky headers. 
    $.tablesorter.defaults.widgets = ['zebra','stickyHeaders'];
  }
  // extend the default setting to always sort on the first column 
    $.tablesorter.defaults.sortList = [[0,0]]; 
    // call the tablesorter plugin 
    $("table").tablesorter();   
} 

);

stickyHeaders を取得してハッシュ行を認識し、ヘッダーの下に表示する方法はありますか?

4

1 に答える 1

0

このコードを追加してみてください ( demo ):

$('a').click(function(){
    if (this.hash !== "") {
        window.location.hash = this.hash;
        // find table that link is inside
        var $table = $(this).closest('table'),
            // get stickheader height + a little extra,
            // if the link is in a table & table has a stickyheader...
            shHeight = ( $table.find('.tablesorter-stickyHeader').parent().height() || 0 ) * 1.2;
        // move the anchor below the sticky header
        $(window).scrollTop( $(window).scrollTop() - shHeight);
        // prevent anchor from controlling the scrollTop
        return false;
    }
});

</p>

于 2012-08-27T03:01:41.210 に答える