floatTitle.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. let floatTitleNum = 0;
  2. let floatTitleMap = new Map();
  3. var floatTitle = (function () {
  4. const setFloatTitle = function () {
  5. const content = $("#content");
  6. const contentTop = content.offset().top;
  7. const contentOuterHeight = content.outerHeight(true); //当前可视的页面高度
  8. //遍历
  9. $('#tableContent tr').each(function () {
  10. const content = $(this).children().eq(0).html();
  11. if (content !== null && content !== undefined && content.length > 0 && content !== " ") {
  12. let cardOffsetTop = $(this).offset().top;
  13. let cardOuterHeight = $(this).outerHeight(true);
  14. if ((cardOffsetTop + cardOuterHeight - 10 > contentTop) &&
  15. (cardOffsetTop < contentTop + contentOuterHeight)) {
  16. const floatTitleDiv = $("#floatTitle");
  17. const value = $(this).data("value");
  18. if (value !== undefined && value !== null) {
  19. floatTitleDiv.removeClass("none");
  20. floatTitleDiv.html(floatTitleMap.get(value));
  21. } else {
  22. $('#floatTitle').addClass("none")
  23. }
  24. return false
  25. }
  26. }
  27. });
  28. }
  29. const setFloatTitleMap = function () {
  30. $('#tableContent tr').each(function () {
  31. const content = $(this).children().eq(0).html();
  32. if (content !== null && content !== undefined && content.length > 0 && content !== "&nbsp;") {
  33. const titleId = $(this).data("title");
  34. if (titleId !== undefined && titleId !== null) {
  35. floatTitleMap.set(titleId, content);
  36. }
  37. }
  38. });
  39. }
  40. //监听上下滚动
  41. const callFloatTitleSetTimeout = function (floatTitleNumTemp) {
  42. if (floatTitleNum === floatTitleNumTemp) {
  43. setFloatTitle();
  44. }
  45. }
  46. const callFloatTitle = function () {
  47. if (floatTitleNum > 100000) {
  48. floatTitleNum = 0;
  49. } else {
  50. floatTitleNum++;
  51. }
  52. const floatTitleNumTemp = floatTitleNum
  53. setTimeout(function () {
  54. callFloatTitleSetTimeout(floatTitleNumTemp)
  55. }, 50);
  56. }
  57. return {callFloatTitle, setFloatTitleMap}
  58. })();