表头:在tr:悬停时显示



我想在这个网站上复制这个效果http://sires.crv4all.us/shop/us/catalog/Holstein

当您将<tr>悬停时,它会在您的光标所在的<tr>行上方显示标题信息。

我尝试使用jQuery工具提示,但它显示头部在顶部。我想知道如何让鼠标悬停时的tr行显示

这是我制作的产生这种效果的jsfiddle(我对JS/jquery有点陌生,所以请随意批评我的代码,我知道它相当低效)。

在页面上看起来是JS在驱动它:

  var $div = $('<div class="floating-header" style="position:absolute;z-index:1;display:none"><table><thead></thead></table></div>');
    $(document.body).prepend($div);
    var $source = $('#animals thead');
    // Lock widths
    $source.find('th').each(function(){
      var $this = $(this);
      $this.css({width: + $this.width() + 'px'});
    })
    // Position floater
    $div.find('thead').append($source.html());
    var offset = $source.offset();
    $div.css({
      left: offset.left,                                                       
      top: offset.top
    })
    // Strip off junk
    $th = $div.find('th');
    var thIdx = 0;
    var thLength = $th.length;
            var cartEnabled = false;
    $th.each(function(){
      var $this = $(this);
      $this.html($this.find('a').text());
      if (thIdx<=2 || (cartEnabled && thIdx==(thLength-1))) $this.css({opacity:0});
      thIdx++;
    });
    // Exclude first row (initial state on page load; updated by facets.js)
    $('#animals tbody tr:visible').first().addClass('no-header');
    var HEADER_HEIGHT = $div.height();
    // Set-up events
    $('#animals tbody tr').mouseover(function(){
      var $row = $(this);
      setMyTimeout(function(){
        if ($row.hasClass('no-header')) return;
        $div.stop().css({
          top: ($row.offset().top - HEADER_HEIGHT) + 'px',
          left: $row.offset().left, 
        opacity: 0.5}).fadeIn(200);
      },100);
    });
    $('#animals tbody tr').mouseout(function(){
      setMyTimeout(function(){
        $div.fadeOut(200);
      },50);
    });
  });

最新更新