xgk.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. $(function () {
  2. // 图片懒加载
  3. $("img").lazyload();
  4. // 显示区高度
  5. let ch = document.documentElement.clientHeight || document.body.clientHeight,
  6. lock = false,
  7. // 加载 数据
  8. currentPage = 3, totalPage = 3,
  9. // 判断请求参数
  10. url = window.location.href,
  11. path = lxd.parseUrl(url).pathname
  12. , reg = /(?<=\/xgk\/).*?(?=.html)/, special_report = !path.match(reg) ? '' : path.match(reg)[0];
  13. $(window).scroll(function () {
  14. if (lock) return false;
  15. // 滑动区高度
  16. let sh = document.documentElement.scrollHeight || document.body.scrollHeight,
  17. // 滑动位置
  18. st = document.documentElement.scrollTop || document.body.scrollTop,
  19. c = sh * 1 - ch * 1 - st * 1;
  20. if (c == 0 && currentPage <= totalPage) {
  21. lock = true;
  22. $(".my-loading").show();
  23. data({ currentPage, special_report }).then(res => { totalPage = res.totalPage; currentPage++; lock = res.lock; $(".my-loading").hide(); })
  24. }
  25. if (c == 0 && currentPage > totalPage) {
  26. $(".my-loading").html("已经没有可以加载的数据了").show();
  27. }
  28. })
  29. // 加载数据
  30. function data (data) {
  31. return new Promise(resolve => {
  32. $.ajax({
  33. url: `http://api.gaokaoapp.net/exampaper/special/h/`,
  34. data: {
  35. ...data,
  36. pageSize: 10
  37. },
  38. type: "get",
  39. error: function (error) {
  40. $(".my-loading").html("已经没有可以加载的数据了")
  41. },
  42. success: function (res) {
  43. let { dataList, totalPage } = res.data;
  44. let father = document.createDocumentFragment();
  45. Array.from(dataList).forEach(
  46. item => {
  47. let str = `<a target="_blank" href="http://www.gaokaoapp.net/h_exam/${item.exampaper_id}.html" class="list-item">
  48. <div class="item-img">
  49. <img data-original="${item.thumbnail}"
  50. src="../imgs/app.png"
  51. alt="">
  52. </div>
  53. <div class="item-detail">
  54. <div class="title">${item.title}</div>
  55. <div class="time">${item.uk}<span>${item.create_time}</span></div>
  56. </div>
  57. </a>`
  58. $(father).append(str);
  59. }
  60. )
  61. $(".list").append(father);
  62. $("img").lazyload();
  63. resolve({ lock: false, totalPage })
  64. }
  65. })
  66. })
  67. }
  68. })