index.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. $(function()
  2. {
  3. /* Set the heights of every block to keep them same height. */
  4. projectBoxHeight = $('#projectbox').height();
  5. productBoxHeight = $('#productbox').height();
  6. if(projectBoxHeight < 180) $('#projectbox').css('height', 180);
  7. if(productBoxHeight < 180) $('#productbox').css('height', 180);
  8. $('.panel-block').scroll(function()
  9. {
  10. var hasFixed = $(this).find('.fixedHead').size() > 0;
  11. if(!hasFixed)
  12. {
  13. $(this).css('position', 'relative');
  14. var hasHeading = $(this).find('.panel-heading').size() > 0;
  15. var fixed = hasHeading ? $(this).find('.panel-heading').clone() : "<table class='fixedHead' style='position:absolute;top:0px;z-index:10'><thead>" + $(this).find('table thead').html() + '</thead></table>';
  16. $(this).prepend(fixed);
  17. if(hasHeading)
  18. {
  19. var firstHeading = $(this).find('.panel-heading:first');
  20. var lastHeading = $(this).find('.panel-heading:last');
  21. firstHeading.addClass('fixedHead');
  22. firstHeading.css({'position':'absolute','top':'0px'});
  23. firstHeading.width(lastHeading.width());
  24. firstHeading.height(lastHeading.height());
  25. }
  26. else
  27. {
  28. var $fixTable = $(this).find('table.fixedHead');
  29. $fixTable.addClass($(this).find('table:last').attr('class'));
  30. var $dataTable = $(this).find('table:last thead th');
  31. $fixTable.find('thead th').each(function(i){$fixTable.find('thead th').eq(i).width($dataTable.eq(i).width());})
  32. }
  33. }
  34. $(this).find('.fixedHead').css('top',$(this).scrollTop());
  35. });
  36. });