affix.html.php 759 B

1234567891011121314151617181920212223242526
  1. <style>
  2. .affix {position:fixed; top:0px; width:95.6%;z-index:10000;}
  3. </style>
  4. <script>
  5. function affix(obj)
  6. {
  7. var fixH = $(obj).offset().top;
  8. var first = true;
  9. $(window).scroll(function()
  10. {
  11. var scroH = $(this).scrollTop();
  12. if(scroH>=fixH && first)
  13. {
  14. $(obj).parent().parent().before("<table class='table table-form' id='headerClone'></table>");
  15. $('#headerClone').append($(obj).clone()).addClass('affix');
  16. $('.table ' + obj + ' th').each(function(i){$('#headerClone ' + obj + ' th').eq(i).width($(this).width())});
  17. first = false;
  18. }
  19. else if(scroH<fixH)
  20. {
  21. $("#headerClone").remove();
  22. first = true;
  23. }
  24. });
  25. }
  26. </script>