load_index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. var goods_page = 1;
  2. var goods_rid = 1;
  3. var is_can_next = 1;
  4. $(function(){
  5. var link = [];
  6. is_can_next = 0;
  7. nextpage();
  8. $('.nav-item').click(function(){
  9. goods_rid = $(this).attr('data-rid');
  10. goods_page = 1;
  11. $(this).addClass('active').siblings().removeClass('active');
  12. //$('#goods_content').html('');
  13. nextpage();
  14. return false;
  15. })
  16. //load best pintuan
  17. $.ajax({
  18. url:load_pintuan_url,
  19. type:'get',
  20. dataType:'json',
  21. success:function(ret)
  22. {
  23. if(ret.code == 1){
  24. var s_data = ret.list;
  25. for(var i in s_data){
  26. var s_tmp = {};
  27. s_tmp.url = s_data[i].url;
  28. s_tmp.fan_image = s_data[i].fan_image;
  29. s_tmp.name = s_data[i].name;
  30. s_tmp.type = s_data[i].type;
  31. s_tmp.pin_price = s_data[i].pin_price;
  32. s_tmp.pin_count = s_data[i].pin_count;
  33. s_tmp.seller_count = s_data[i].seller_count;
  34. link.push(s_tmp);
  35. }
  36. bindImgEvent();
  37. $('#best_pintuan').tmpl(link).appendTo('#best_pintuan_wrap');
  38. }
  39. }
  40. })
  41. //load best goods
  42. $(window).scroll( function() {
  43. loaddata();
  44. });
  45. })
  46. var cur_url = "{:U('Index/index')}";
  47. function loaddata()
  48. {
  49. var totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop()); //浏览器的高度加上滚动条的高度
  50. if ($(document).height() <= totalheight+200) //当文档的高度小于或者等于总的高度的时候,开始动态加载数据
  51. {
  52. if(is_can_next == 1)//加载数据
  53. {
  54. is_can_next = 0;
  55. nextpage();
  56. }
  57. }
  58. }
  59. function load_caini_xihuan()
  60. {
  61. $.ajax(
  62. {
  63. url: load_suiji_url,
  64. type:'post',
  65. data:{},
  66. dataType: 'json',
  67. success: function(ret){
  68. if(ret.code == 1)
  69. {
  70. //id="m123585"
  71. if(ret.html != ''){
  72. $('#suiji_goods_content').html(ret.html);
  73. $('#guss_box').show();
  74. $('#m123585').show();
  75. bindImgEvent();
  76. }
  77. } else if(result.code == 0) {
  78. }
  79. }
  80. })
  81. }
  82. function nextpage()
  83. {
  84. $('#center_pullup').show();
  85. $.ajax(
  86. {
  87. url: load_goods_url,
  88. type:'post',
  89. data:{page:goods_page,goods_rid:goods_rid},
  90. dataType: 'json',
  91. success: function(ret){
  92. var links = [];
  93. if(ret.code == 1)
  94. {
  95. var s_data = ret.list;
  96. for(var i in s_data){
  97. var s_tmp = {};
  98. s_tmp.url = s_data[i].url;
  99. s_tmp.image = s_data[i].fan_image;
  100. s_tmp.name = s_data[i].name;
  101. s_tmp.danprice = s_data[i].danprice;
  102. s_tmp.seller_count = s_data[i].seller_count;
  103. links.push(s_tmp);
  104. }
  105. if(goods_page== 1)
  106. {
  107. $('#goods_content').html('');
  108. }
  109. console.log('next_page:..');
  110. console.log(links);
  111. $('#best_goods').tmpl(links).appendTo('#goods_content');
  112. goods_page++;
  113. is_can_next = 1;
  114. bindImgEvent();
  115. } else if(ret.code == 0) {
  116. load_caini_xihuan();
  117. }
  118. }
  119. }
  120. );
  121. }