continuesLoadPage.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. $('#content').append('<div id="content-draw-line" class="content-draw-line none">我是有底线的...</div>');
  2. const pageCount = parseInt($(".get_page_count").html());
  3. let page = parseInt($(".get_page").html());
  4. let isLoadPage = false;
  5. let isCachePage = false;
  6. let isTimeCachePageUp = false;
  7. //监听上下滚动
  8. let loadPageP = 0, loadPageT = 0;
  9. let cachePage = 1;
  10. let cachePageData = [$('#tableContent').html()];
  11. const continuesLoadPage = (function () {
  12. const loadPageSkip = function () {
  13. if (isLoadPage) return
  14. if (page >= pageCount) return
  15. const tableContentHeight = $('#tableContent').height(); //内容高度
  16. const content = $("#content");
  17. const scrollTop = parseInt(content.scrollTop()); //滚动条距离顶部的高度
  18. const clientHeight = content.height(); //当前可视的页面高度
  19. if (tableContentHeight - scrollTop < clientHeight * 2) {
  20. isLoadPage = true;
  21. let jumpNumber = page + 1;
  22. alert("JumpPage@" + jumpNumber);
  23. }
  24. };
  25. const showBottomLine = function () {
  26. if (cachePage === pageCount) {
  27. $('#content-draw-line').removeClass('none');
  28. } else {
  29. $('#content-draw-line').addClass('none');
  30. }
  31. }
  32. const cachePageUp = function () {
  33. isCachePage = true;
  34. const oldChildArray = [];
  35. let height = 0;
  36. for (let i = -10; i < 0; i++) {
  37. const child = $('#tableContent tr').eq(i);
  38. height += child.outerHeight(true)
  39. oldChildArray.push(child);
  40. }
  41. const tableContent = $('#tableContent');
  42. const content = $('#content');
  43. tableContent.html('');
  44. tableContent.append(oldChildArray);
  45. content.scrollTop(height)
  46. cachePage++;
  47. tableContent.append(cachePageData[cachePage - 1]);
  48. if (typeof (floatTitle) !== "undefined") floatTitle.setFloatTitleMap()
  49. setTimeout(function () {
  50. content.scrollTop(height)
  51. setTimeout(function () {
  52. isCachePage = false;
  53. }, 100);
  54. }, 100);
  55. showBottomLine();
  56. }
  57. const cachePageDown = function () {
  58. isCachePage = true;
  59. const tableContent = $('#tableContent');
  60. const content = $("#content");
  61. let height = 0;
  62. for (let i = 0; i < 10; i++) {
  63. const child = $('#tableContent tr').eq(i);
  64. height += child.outerHeight(true)
  65. }
  66. if ((/iosee/.test(navigator.userAgent)) && window.screen.width === 320) {
  67. cachePage--;
  68. tableContent.html(cachePageData[cachePage - 1]);
  69. content.scrollTop(content.height() * 2)
  70. setTimeout(function () {
  71. const loadPageB = tableContent.height() - content.height() - height
  72. content.scrollTop(loadPageB)
  73. setTimeout(function () {
  74. isCachePage = false;
  75. }, 500);
  76. }, 300);
  77. } else {
  78. tableContent.html("");
  79. content.scrollTop(content.height())
  80. cachePage--;
  81. tableContent.html(cachePageData[cachePage - 1]);
  82. setTimeout(function () {
  83. const loadPageB = tableContent.height() - content.height() - height
  84. content.scrollTop(loadPageB)
  85. setTimeout(function () {
  86. isCachePage = false;
  87. }, 100);
  88. }, 100);
  89. }
  90. showBottomLine();
  91. }
  92. const setTimeCachePageUp = function () {
  93. if (!isTimeCachePageUp) return;
  94. if (cachePageData.length > cachePage) {
  95. cachePageUp()
  96. } else {
  97. setTimeout(function () {
  98. setTimeCachePageUp()
  99. }, 300);
  100. }
  101. }
  102. const contentScroll = function () {
  103. if (isCachePage) return;
  104. const content = $("#content");
  105. loadPageP = content.scrollTop();
  106. if (loadPageT <= loadPageP) {
  107. const loadPageB = $('#tableContent').height() - content.height()
  108. if (loadPageP >= loadPageB) {
  109. isTimeCachePageUp = true;
  110. setTimeCachePageUp();
  111. }
  112. if (cachePageData.length === cachePage) {
  113. loadPageSkip();
  114. }
  115. } else {
  116. isTimeCachePageUp = false;
  117. if (loadPageP <= 0) {
  118. if (cachePage > 1) {
  119. cachePageDown();
  120. }
  121. }
  122. }
  123. setTimeout(function () {
  124. loadPageT = loadPageP;
  125. }, 0);
  126. }
  127. return {contentScroll};
  128. })();
  129. $("#content").scroll(function () {
  130. continuesLoadPage.contentScroll();
  131. if (typeof (floatTitle) !== "undefined") floatTitle.callFloatTitle()
  132. });
  133. function loadPage(data) {
  134. let pageData = ''
  135. if (typeof (data) === "string") {
  136. pageData = data.replace(new RegExp("\\\\\"", "gm"), "\"");
  137. } else {
  138. pageData = data.data;
  139. }
  140. page++;
  141. cachePageData[page - 1] = pageData;
  142. isLoadPage = false;
  143. }
  144. if (typeof (floatTitle) !== "undefined") floatTitle.setFloatTitleMap()