index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. $(".sec-01__slider").slick({
  2. dots: true,
  3. autoplay: false,
  4. arrows: false,
  5. });
  6. let result;
  7. $.ajax({
  8. method: "GET",
  9. url: "http://127c-2001-b011-a003-3829-9578-a4a5-7554-1502.ngrok.io/genjson",
  10. dataType: "json",
  11. }).done(function (msg) {
  12. result = [...msg];
  13. renderSec00(result);
  14. renderSec02(result);
  15. renderSec03(result);
  16. renderSec06(result);
  17. renderSec07(result);
  18. renderSec08(result);
  19. renderSec09(result);
  20. renderSec10(result);
  21. renderSec11(result);
  22. renderVideo(result);
  23. });
  24. function renderSec00(data) {
  25. let temp = data[0]['data'];
  26. renderBannerStr('sec-00__slider', temp);
  27. $(".sec-00__slider").slick({
  28. dots: false,
  29. speed: 800,
  30. autoplay: true,
  31. });
  32. }
  33. function renderSec02(data) {
  34. let temp = data[1]['data'];
  35. renderBannerStr('sec-02__slider', temp);
  36. let str = '';
  37. $(".sec-02__slider").slick({
  38. dots: false,
  39. autoplay: true,
  40. arrows: true,
  41. fade: true,
  42. autoplaySpeed: 4000,
  43. });
  44. }
  45. function renderBannerStr(sec, data) {
  46. let str = '';
  47. for(let i = 0; i < data.length; i++){
  48. str+= `<div class="${sec}-${i+1} slide-item" onclick="window.open('${data[i]['link']}');" style="background-image: url('${data[i]['imgUrl']}');"></div>`
  49. }
  50. console.log(str);
  51. $(`.${sec}`).html(str);
  52. }
  53. function renderSec03(data) {
  54. let randomIdx = Math.floor(Math.random()*3);
  55. const ran = $('.sec-03__tabdiv .nav-item-link').eq(randomIdx);
  56. const ranDiv = $('#pills-tabContent .tab-pane').eq(randomIdx);
  57. ran.addClass('active');
  58. ranDiv.addClass('active');
  59. ranDiv.addClass('show');
  60. let temp = data[2]['data'];
  61. for(let i = 0; i < temp.length; i++){
  62. if(temp[i]["tab"] == '最夯設計'){
  63. let str = '';
  64. let sub = temp[i]["data"];
  65. for(let j = 0; j < sub.length; j++){
  66. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}')";>
  67. <div class="tabpar__card__imgfr"><img class="tabpar__card__img" src="${sub[j]['imgUrl']}" alt=""></div>
  68. <p class="mt-2 pe-2">${sub[j]['description']}</p>
  69. </div>`
  70. }
  71. $('#pills-hot .tabpar').html(str);
  72. }
  73. if(temp[i]["tab"] == '影音實錄'){
  74. let str = '';
  75. let sub = temp[i]["data"];
  76. for(let j = 0; j < sub.length; j++){
  77. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}')";>
  78. <div class="tabpar__card__imgfr"><img class="tabpar__card__img" src="${sub[j]['imgUrl']}" alt=""><img class="tabpar__card__play" src="images/Play-Button.png"></div>
  79. <p class="mt-2 pe-2">${sub[j]['description']}</p>
  80. </div>`
  81. }
  82. $('#pills-video .tabpar').html(str);
  83. }
  84. if(temp[i]["tab"] == '專欄文章'){
  85. let str = '';
  86. let sub = temp[i]["data"];
  87. for(let j = 0; j < sub.length; j++){
  88. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}')";>
  89. <div class="tabpar__card__imgfr"><img class="tabpar__card__img" src="${sub[j]['imgUrl']}" alt=""></div>
  90. <p class="mt-2 pe-2">${sub[j]['description']}</p>
  91. </div>`
  92. }
  93. $('#pills-blog .tabpar').html(str);
  94. }
  95. }
  96. const cardText = document.querySelectorAll('.tabpar__card p');
  97. cardText.forEach((item, i) => {
  98. let len = item.textContent.length;
  99. if(len > 20) {
  100. let str = item.textContent.substring(0, 20) + '...';
  101. item.textContent = str;
  102. }
  103. })
  104. }
  105. function renderSec06(data) {
  106. let temp = data[3]['data'];
  107. let str = '';
  108. for(let i = 0; i < temp.length; i++){
  109. if(i === 0) {
  110. str+= `<div class="carousel-item active" onclick="window.open('${temp[i]['link']}');"
  111. style="background-image: url('${temp[i]['imgUrl']}');">
  112. </div>`
  113. } else {
  114. str+= `<div class="carousel-item" onclick="window.open('${temp[i]['link']}');"
  115. style="background-image: url('${temp[i]['imgUrl']}');">
  116. </div>`
  117. }
  118. }
  119. $('.sec-06 .carousel-inner').html(str);
  120. }
  121. function renderSec07(data) {
  122. let temp = data[4]['data'];
  123. let str = '';
  124. for(let i = 0; i < temp.length; i++){
  125. str+= `
  126. <div class="sec-07__slider-${i+1} sec-07__card col-12 mx-1" onclick="window.open('${temp[i]['link']}');">
  127. <div class="sec-07__imgfr mb-2"><img src="${temp[i]['imgUrl']}" alt=""></div>
  128. <p class="sec-07__cardtxt">${temp[i]['description']}</p>
  129. </div>`
  130. }
  131. $('.sec-07__slider').html(str);
  132. $(".sec-07__slider").slick({
  133. arrows: false,
  134. slidesToShow: 1,
  135. centerMode: true,
  136. infinite: false,
  137. dots: true,
  138. centerPadding: '12px'
  139. });
  140. const cardText = document.querySelectorAll('.sec-07__cardtxt');
  141. cardText.forEach((item, i) => {
  142. let len = item.textContent.length;
  143. if(len > 20) {
  144. let str = item.textContent.substring(0, 25) + '...';
  145. item.textContent = str;
  146. }
  147. })
  148. }
  149. function renderSec08(data) {
  150. let temp = data[5]['data'];
  151. let str = '';
  152. for(let i = 0; i < temp.length; i++){
  153. str+= `<div class="sec-08__slider-${i+1} mx-1 slide-item" style="width: 70vw; background-image: url('${temp[i]['imgUrl']}');" onclick="window.open('${temp[i]['link']}');"></div>`
  154. }
  155. $('.sec-08__slider').html(str);
  156. $(".sec-08__slider").slick({
  157. arrows: false,
  158. slidesToShow: 1,
  159. centerMode: true,
  160. infinite: false,
  161. dots: false,
  162. centerPadding: '12px'
  163. });
  164. }
  165. function renderSec09(data) {
  166. let temp = data[6]['data'];
  167. let str = '';
  168. for(let i = 0; i < temp.length; i++){
  169. str+= `<div class="sec-09__card" onclick="window.open('${temp[i]['link']}');">
  170. <div class="sec-09__card__imgfr"><img src="${temp[i]['imgUrl']}" alt=""></div>
  171. <p>${temp[i]['description']}</p>
  172. </div>`
  173. }
  174. $('.sec-09__cardgrp').html(str);
  175. }
  176. function renderSec10(data) {
  177. let temp = data[7]['data'];
  178. renderRecStr('sec-10', temp);
  179. }
  180. function renderSec11(data) {
  181. let temp = data[8]['data'];
  182. renderRecStr('sec-11', temp);
  183. }
  184. function renderRecStr(sec, data) {
  185. let str = '';
  186. for(let i = 0; i < data.length; i++){
  187. if(data[i].video == 'true') {
  188. str+= `<div class="${sec}__card col-12 mx-1" onclick="window.open('${data[i]['link']}');">
  189. <div class="${sec}__slider-${i+1} mb-2 slide-item" style="background-image: url('${data[i]['imgUrl']}');"><img class="${sec}__card__play" src="images/Play-Button.png"></div>
  190. <p class="${sec}__cardtxt">${data[i]['description']}</p>
  191. </div>`;
  192. } else {
  193. str+= `<div class="${sec}__card col-12 mx-1" onclick="window.open('${data[i]['link']}');">
  194. <div class="${sec}__slider-${i+1} mb-2 slide-item" style="background-image: url('${data[i]['imgUrl']}');"></div>
  195. <p class="${sec}__cardtxt">${data[i]['description']}</p>
  196. </div>`;
  197. }
  198. }
  199. $(`.${sec}__slider`).html(str);
  200. $(`.${sec}__slider`).slick({
  201. arrows: false,
  202. slidesToShow: 1,
  203. centerMode: true,
  204. infinite: false,
  205. dots: false,
  206. centerPadding: '12px'
  207. });
  208. }
  209. function renderVideo(data) {
  210. let temp = data[9];
  211. $('.sec-05__video__txt').text(temp['title']);
  212. $('.sec-05__video__imgfr').css('background-image', `url(https://img.youtube.com/vi/${temp['yt']}/hqdefault.jpg)`);
  213. $('#videoModal').on('shown.bs.modal', function () {
  214. $('#videoModal iframe').attr('src', `https://www.youtube.com/embed/${temp['yt']}?controls=0&autoplay=1&amp;enablejsapi=1&amp;origin=https%3A%2F%2Fm.hhh.com.tw&amp;widgetid=1`);
  215. });
  216. $('#videoModal').on('hidden.bs.modal', function () {
  217. $('#videoModal iframe').removeAttr('src');
  218. });
  219. }
  220. window.addEventListener('scroll', fixedOnScroll);
  221. const navbar = document.querySelector('.navbar-main');
  222. function fixedOnScroll() {
  223. const sticky = 110;
  224. if(window.pageYOffset >= sticky){
  225. navbar.classList.add('sticky');
  226. } else {
  227. navbar.classList.remove('sticky');
  228. }
  229. }
  230. $('.navbar-toggler').click(function(){
  231. $(".sec-menu").css('display', 'block');
  232. $(".wholeBody").css('overflow-y', 'hidden');
  233. });
  234. $('.navbar-back').click(function(){
  235. $(".sec-menu").css('display', 'none');
  236. $(".wholeBody").css('overflow-y', 'scroll');
  237. });
  238. $('.subexpand').click(function(){
  239. $(this).parent().next().toggleClass('show');
  240. $(this).parent().toggleClass('show');
  241. });
  242. $('.navbar-search').click(function(){
  243. $(".sec-search").css('display', 'block');
  244. $(".wholeBody").css('overflow-y', 'hidden');
  245. })
  246. $('.navbar-backs').click(function(){
  247. $(".sec-search").css('display', 'none');
  248. $(".wholeBody").css('overflow-y', 'scroll');
  249. });
  250. $('.navbar-back-fav').click(function(){
  251. $(".sec-favor").css('display', 'none');
  252. })
  253. $('.btn-gotop').click(function () {
  254. $('html, body').animate({
  255. scrollTop: 0
  256. }, 500)
  257. });
  258. $(window).scroll(function() {
  259. if ( $(this).scrollTop() > 500 ){
  260. $('.fixed-btn').fadeIn(222);
  261. } else {
  262. $('.fixed-btn').stop().fadeOut(222);
  263. }
  264. }).scroll();
  265. const searchBtn = document.querySelector('.searchBtn');
  266. const searchBar = document.querySelector('.searchBar');
  267. const searchHotLink = document.querySelectorAll('.sec-search-hots__link');
  268. searchBtn.addEventListener('click', search);
  269. searchBar.addEventListener('keyup', pressSearch);
  270. function search() {
  271. if(searchBar.value == '') {
  272. window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
  273. } else {
  274. window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
  275. }
  276. }
  277. function pressSearch(e) {
  278. if (e.keyCode === 13) {
  279. e.preventDefault();
  280. search();
  281. }
  282. }
  283. searchHotLink.forEach((item, i) => {
  284. item.addEventListener('click', function() {
  285. window.location.href = `https://m.hhh.com.tw/search/lists/case/${this.textContent}-keyword/`;
  286. })
  287. })
  288. //jQuery time
  289. var current_fs, next_fs, previous_fs; //fieldsets
  290. var left, opacity, scale; //fieldset properties which we will animate
  291. var animating; //flag to prevent quick multi-click glitches
  292. $(".next").click(function(){
  293. if(animating) return false;
  294. animating = true;
  295. current_fs = $(this).parent().parent();
  296. next_fs = $(this).parent().parent().next();
  297. //activate next step on progressbar using the index of next_fs
  298. $(".form-progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  299. //show the next fieldset
  300. next_fs.animate({opacity: 1}, {
  301. step: function(now, mx) {
  302. //as the opacity of current_fs reduces to 0 - stored in "now"
  303. //1. scale current_fs down to 80%
  304. scale = 0 + (1 + now) * .5 ;
  305. //2. bring next_fs from the right(50%)
  306. left = (now * 50)+"%";
  307. //3. increase opacity of next_fs to 1 as it moves in
  308. opacity = 0 + now;
  309. next_fs.css({
  310. 'transform': 'scale('+scale+')',
  311. });
  312. next_fs.css({'opacity': opacity});
  313. },
  314. duration: 400,
  315. complete: function(){
  316. next_fs.show();
  317. animating = false;
  318. },
  319. //this comes from the custom easing plugin
  320. easing: 'easeInOutBack'
  321. });
  322. //hide the current fieldset with style
  323. current_fs.animate({opacity: 0}, {
  324. step: function(now, mx) {
  325. //as the opacity of current_fs reduces to 0 - stored in "now"
  326. //1. scale current_fs down to 80%
  327. scale = 1 - (1 - now) * 0.2;
  328. //2. bring next_fs from the right(50%)
  329. left = (now * 50)+"%";
  330. //3. increase opacity of next_fs to 1 as it moves in
  331. opacity = 1 - now;
  332. current_fs.css({
  333. 'transform': 'scale('+scale+')',
  334. });
  335. next_fs.css({'opacity': opacity});
  336. },
  337. duration: 400,
  338. complete: function(){
  339. current_fs.hide();
  340. animating = false;
  341. },
  342. //this comes from the custom easing plugin
  343. easing: 'easeInOutBack'
  344. });
  345. });