columns.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. // $(".popular").hide();
  2. $(document).on("click", ".likeSee__state__filter--item", function (event) {
  3. // $(".News").toggle();
  4. // $(".popular").toggle();
  5. $(".likeSee__state__filter--item").removeClass('active');
  6. $(this).addClass("active");
  7. });
  8. const urlParams = new URLSearchParams(window.location.search);
  9. let id = urlParams.get('cid');
  10. console.log(id);
  11. function get_data() {
  12. $.ajax({
  13. method: "GET",
  14. // url: `json/Columns-${id}.json`,
  15. url: `https://m3.hhh.com.tw:18686/gencolumn?id=${id}&sort=new&page=1`,
  16. // url:`json/Columns.json`,
  17. dataType: "json",
  18. })
  19. .done(function (msg) {
  20. console.log(msg);
  21. let ColumnsContent = "";
  22. let ColumnsTag = "";
  23. let breadcrumbTitle = "";
  24. let article_info = "";
  25. let OtherColumns = "";
  26. let PopularColumns = "";
  27. let author_inf="";
  28. breadcrumbTitle = `<a href="#">${msg[0].Columnstitle}</a>`
  29. article_info = `
  30. <h1 class="article__title mt-4">${msg[0].Columnstitle}</h1>
  31. <div class="small">${msg[0].ColumnsDate}| 人氣:${msg[0].ColumnsViews}</div>
  32. `;
  33. ColumnsContent = `${msg[0].ColumnsContent}`;
  34. for (let j = 0; j < msg[0].ColumnsTag.length; j++) {
  35. ColumnsTag += ' \
  36. <a target="_blank" href="https://hhh.com.tw/cases/lists/' + msg[0].ColumnsTag[j].Tag + '-keyword/" \
  37. class="btn btn-outline-custom rounded-0">'
  38. + msg[0].ColumnsTag[j].Tag + '</a>';
  39. }
  40. for (let i = 0; i < 12; i++) {
  41. OtherColumns +=
  42. '<div class="col-12 col-md-4 ps-0"><div class="cardList__items">\
  43. <a target="_blank" href="https://hhh.com.tw/columns/detail/'+ msg[0].OtherColumns[i].Columnsid + '/"> <img src="' + msg[0].OtherColumns[i].ColumnsCoverImg + '" alt="">\
  44. <div class="cardList__items__content">\
  45. <a href="https://hhh.com.tw/columns/detail/'+ msg[0].OtherColumns[i].Columnsid + '/"" target="_blank">\
  46. <div class="cardList__items--title cardList__items--ellipse">\
  47. '+ msg[0].OtherColumns[i].Columnstitle + '\
  48. </div>\
  49. </a>'
  50. OtherColumns += '<p>'
  51. for (k = 0; k < msg[0].OtherColumns[i].ColumnsTag.length; k++) {
  52. OtherColumns += '\
  53. <a class="likeSee__tag--item" href="https://hhh.com.tw/columns/lists/'+ msg[0].OtherColumns[i].ColumnsTag[k].tag + '-keyword/all-columntypea/" arget="_blank">' + msg[0].OtherColumns[i].ColumnsTag[k].Tag + '</a>'
  54. }
  55. OtherColumns += '</p>'
  56. OtherColumns += '</div></div></div>'
  57. }
  58. author_inf=`
  59. <div>
  60. ${msg[0].author_inf}
  61. </div>
  62. `;
  63. // for(let i=0; i<msg[0].PopularColumns.length; i++){
  64. // PopularColumns+=
  65. // '<div class="col-12 col-md-4 ps-0"><div class="cardList__items">\
  66. // <a target="_blank" href="https://hhh.com.tw/columns/detail/'+msg[0].PopularColumns[i].Columnsid+'/"> <img src="'+msg[0].PopularColumns[i].ColumnsCoverImg+'" alt="">\
  67. // <div class="cardList__items__content">\
  68. // <a href="https://hhh.com.tw/columns/detail/'+msg[0].PopularColumns[i].Columnsid+'/"" target="_blank">\
  69. // <div class="cardList__items--title cardList__items--ellipse">\
  70. // '+msg[0].PopularColumns[i].Columnstitle+'\
  71. // </div>\
  72. // </a>'
  73. // PopularColumns+='<p>'
  74. // for(k=0; k<msg[0].PopularColumns[i].ColumnsTag.length; k++){
  75. // PopularColumns+='\
  76. // <a class="likeSee__tag--item" href="https://hhh.com.tw/columns/lists/'+msg[0].PopularColumns[i].ColumnsTag[k].tag+'-keyword/all-columntypea/" arget="_blank">'+msg[0].PopularColumns[i].ColumnsTag[k].Tag+'</a>'
  77. // }
  78. // PopularColumns+='</p>'
  79. // PopularColumns+='</div></div></div>'
  80. // }
  81. $('.article_info').html(article_info);
  82. $('.breadcrumb-title').html(breadcrumbTitle);
  83. $('.ColumnsContent').html(ColumnsContent);
  84. $('.ColumnsTag').html(ColumnsTag);
  85. $('.OtherColumns').html(OtherColumns);
  86. $('.anchor_info').html(author_inf);
  87. // $('.PopularColumns').html(PopularColumns);
  88. });
  89. }
  90. function renderSec07() {
  91. $.ajax({
  92. method: "GET",
  93. // url: `json/bannerAds-${id}.json`,
  94. url: `https://m3.hhh.com.tw:18686/getColumnAds`,
  95. dataType: "json",
  96. })
  97. .done(function (msg) {
  98. console.log(msg);
  99. console.log(msg.length);
  100. let str = '';
  101. for (let i = 0; i < msg.length; i++) {
  102. str += `<div class="sec-07__slider-${i + 1} slide-item p-1" onclick="window.open('${msg[i].link}');" data-bg="${msg[i].imgUrl}"><img class="img-fluid" src="${msg[i].imgUrl}"></div>`
  103. }
  104. $(`.sec-07__slider`).html(str);
  105. $(".sec-07__slider").slick({
  106. dots: false,
  107. autoplay: true,
  108. arrows: true,
  109. slidesToShow: 4,
  110. slidesToScroll: 1,
  111. autoplaySpeed: 7000,
  112. initialSlide: 0,
  113. infinite: true,
  114. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
  115. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>'
  116. });
  117. });
  118. }
  119. get_data();
  120. renderSec07();
  121. let filter;
  122. $(".views").click(function () {
  123. console.log(1);
  124. filter = "hot";
  125. get_views_data();
  126. });
  127. $(".recently").click(function () {
  128. console.log(2);
  129. filter = "new";
  130. get_views_data();
  131. });
  132. function get_views_data() {
  133. $.ajax({
  134. method: "GET",
  135. url:`https://m3.hhh.com.tw:18686/gencolumn?id=${id}&sort=${filter}&page=1`,
  136. // url: `json/Columns-${id}.json`,
  137. // url:`json/cases.json`,
  138. dataType: "json",
  139. })
  140. .done(function (msg) {
  141. console.log(msg);
  142. // msg[0].OtherColumns.sort(function (a, b) {
  143. // return a['Views'] > b['Views'] ? -1 : 1;
  144. // });
  145. console.log(msg[0].OtherColumns);
  146. let OtherColumns = "";
  147. for (let i = 0; i < msg[0].OtherColumns.length; i++) {
  148. OtherColumns +=
  149. '<div class="col-12 col-md-4 ps-0"><div class="cardList__items">\
  150. <a target="_blank" href="https://hhh.com.tw/columns/detail/'+ msg[0].OtherColumns[i].Columnsid + '/"> <img src="' + msg[0].OtherColumns[i].ColumnsCoverImg + '" alt="">\
  151. <div class="cardList__items__content">\
  152. <a href="https://hhh.com.tw/columns/detail/'+ msg[0].OtherColumns[i].Columnsid + '/"" target="_blank">\
  153. <div class="cardList__items--title cardList__items--ellipse">\
  154. '+ msg[0].OtherColumns[i].Columnstitle + '\
  155. </div>\
  156. </a>'
  157. OtherColumns += '<p>'
  158. for (k = 0; k < msg[0].OtherColumns[i].ColumnsTag.length; k++) {
  159. OtherColumns += '\
  160. <a class="likeSee__tag--item" href="https://hhh.com.tw/columns/lists/'+ msg[0].OtherColumns[i].ColumnsTag[k].tag + '-keyword/all-columntypea/" arget="_blank">' + msg[0].OtherColumns[i].ColumnsTag[k].Tag + '</a>'
  161. }
  162. OtherColumns += '</p>'
  163. OtherColumns += '</div></div></div>'
  164. }
  165. $('.OtherColumns').html(OtherColumns);
  166. });
  167. };
  168. if ($(".views").hasClass("active")) {
  169. filter = "hot";
  170. // alert('1');
  171. } else {
  172. filter = "new";
  173. // alert('2');
  174. }
  175. function scroll_bottom_load_data(page) {
  176. $.ajax({
  177. method: "GET",
  178. // url: `json/cases-${id}.json`,
  179. // url:`json/cases.json`,
  180. url: `https://m3.hhh.com.tw:18686/gencolumn?id=${id}&sort=${filter}&page=${page}`,
  181. dataType: "json",
  182. })
  183. .done(function (msg) {
  184. let OtherColumns = "";
  185. for (let i = 0; i < msg[0].OtherColumns.length; i++) {
  186. OtherColumns +=
  187. '<div class="col-12 col-md-4 ps-0"><div class="cardList__items">\
  188. <a target="_blank" href="https://hhh.com.tw/columns/detail/'+ msg[0].OtherColumns[i].Columnsid + '/"> <img src="' + msg[0].OtherColumns[i].ColumnsCoverImg + '" alt="">\
  189. <div class="cardList__items__content">\
  190. <a href="https://hhh.com.tw/columns/detail/'+ msg[0].OtherColumns[i].Columnsid + '/"" target="_blank">\
  191. <div class="cardList__items--title cardList__items--ellipse">\
  192. '+ msg[0].OtherColumns[i].Columnstitle + '\
  193. </div>\
  194. </a>'
  195. OtherColumns += '<p>'
  196. for (k = 0; k < msg[0].OtherColumns[i].ColumnsTag.length; k++) {
  197. OtherColumns += '\
  198. <a class="likeSee__tag--item" href="https://hhh.com.tw/columns/lists/'+ msg[0].OtherColumns[i].ColumnsTag[k].tag + '-keyword/all-columntypea/" arget="_blank">' + msg[0].OtherColumns[i].ColumnsTag[k].Tag + '</a>'
  199. }
  200. OtherColumns += '</p>'
  201. OtherColumns += '</div></div></div>'
  202. }
  203. // $('.OtherColumns').html(OtherColumns);
  204. $('.OtherColumns').append(OtherColumns);
  205. });
  206. }
  207. $(window).scroll(function () {
  208. var scrollTop = $(this).scrollTop();
  209. var scrollHeight = $('body').prop("scrollHeight");
  210. var clientHeight = document.documentElement.clientHeight;
  211. if (jQuery(window).width() < 767) {
  212. //一樣 var scrollHeight2 = document.documentElement.scrollHeight;
  213. if (scrollTop + clientHeight >= scrollHeight - 5) {
  214. loadMore_m();
  215. console.log(page);
  216. }
  217. } else {
  218. if (scrollTop + clientHeight >= scrollHeight - 5) {
  219. loadMore();
  220. console.log(page);
  221. }
  222. }
  223. })
  224. var page = 1;
  225. function loadMore() {
  226. setTimeout(function () {
  227. page++;
  228. // console.log(page);
  229. scroll_bottom_load_data(page);
  230. return page
  231. }, 500);
  232. }
  233. function loadMore_m() {
  234. // console.log(page);
  235. setTimeout(function () {
  236. page++;
  237. // console.log(page);
  238. scroll_bottom_load_data(page);
  239. return page
  240. }, 500);
  241. }
  242. // function loadMore_m() {
  243. // // console.log(page);
  244. // setTimeout(function () {
  245. // page++;
  246. // // console.log(page);
  247. // scroll_bottom_load_data(page);
  248. // return page
  249. // }, 500);
  250. // }