index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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: "../json/data.json",
  10. dataType: "json",
  11. }).done(function (msg) {
  12. result = [...msg];
  13. console.log(result);
  14. renderSec00(result);
  15. renderSec02(result);
  16. renderSec03(result);
  17. renderSec06(result);
  18. renderSec07(result);
  19. renderSec08(result);
  20. renderSec09(result);
  21. renderSec10(result);
  22. renderSec11(result);
  23. });
  24. function renderSec00(data) {
  25. let temp = data[0]['data'];
  26. let str = '';
  27. for(let i = 0; i < temp.length; i++){
  28. console.log(temp[i]['imgUrl']);
  29. str+= `<div class="sec-00__slider-${i+1}" onclick="window.open('${temp[i]['link']}');" style="background-image: url('${temp[i]['imgUrl']}');"></div>`
  30. }
  31. $('.sec-00__slider').html(str);
  32. $(".sec-00__slider").slick({
  33. dots: false,
  34. speed: 800,
  35. autoplay: true,
  36. });
  37. }
  38. function renderSec02(data) {
  39. let temp = data[1]['data'];
  40. let str = '';
  41. for(let i = 0; i < temp.length; i++){
  42. console.log(temp[i]['imgUrl']);
  43. str+= `<div class="sec-02__slider-${i+1}" onclick="window.open('${temp[i]['link']}');" style="background-image: url('${temp[i]['imgUrl']}');"></div>`
  44. }
  45. $('.sec-02__slider').html(str);
  46. $(".sec-02__slider").slick({
  47. dots: false,
  48. autoplay: true,
  49. arrows: true,
  50. fade: true,
  51. autoplaySpeed: 4000,
  52. });
  53. }
  54. function renderSec03(data) {
  55. let temp = data[2]['data'];
  56. for(let i = 0; i < temp.length; i++){
  57. if(temp[i]["tab"] == '最夯設計'){
  58. let str = '';
  59. let sub = temp[i]["data"];
  60. for(let j = 0; j < sub.length; j++){
  61. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}')";>
  62. <div class="tabpar__card__imgfr"><img class="tabpar__card__img" src="${sub[j]['imgUrl']}" alt=""></div>
  63. <p class="mt-2 pe-2">${sub[j]['description']}</p>
  64. </div>`
  65. }
  66. $('#pills-hot .tabpar').html(str);
  67. }
  68. if(temp[i]["tab"] == '影音實錄'){
  69. let str = '';
  70. let sub = temp[i]["data"];
  71. for(let j = 0; j < sub.length; j++){
  72. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}')";>
  73. <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>
  74. <p class="mt-2 pe-2">${sub[j]['description']}</p>
  75. </div>`
  76. }
  77. $('#pills-video .tabpar').html(str);
  78. }
  79. if(temp[i]["tab"] == '專欄文章'){
  80. let str = '';
  81. let sub = temp[i]["data"];
  82. for(let j = 0; j < sub.length; j++){
  83. str+= `<div class="tabpar__card" onclick="window.open('${sub[j]['link']}')";>
  84. <div class="tabpar__card__imgfr"><img class="tabpar__card__img" src="${sub[j]['imgUrl']}" alt=""></div>
  85. <p class="mt-2 pe-2">${sub[j]['description']}</p>
  86. </div>`
  87. }
  88. $('#pills-blog .tabpar').html(str);
  89. }
  90. }
  91. const cardText = document.querySelectorAll('.tabpar__card p');
  92. cardText.forEach((item, i) => {
  93. let len = item.textContent.length;
  94. if(len > 20) {
  95. let str = item.textContent.substring(0, 20) + '...';
  96. item.textContent = str;
  97. }
  98. })
  99. }
  100. function renderSec06(data) {
  101. let temp = data[3]['data'];
  102. let str = '';
  103. for(let i = 0; i < temp.length; i++){
  104. console.log(temp[i]['imgUrl']);
  105. if(i === 0) {
  106. str+= `<div class="carousel-item active" onclick="window.open('${temp[i]['link']}');"
  107. style="background-image: url('${temp[i]['imgUrl']}');">
  108. </div>`
  109. } else {
  110. str+= `<div class="carousel-item" onclick="window.open('${temp[i]['link']}');"
  111. style="background-image: url('${temp[i]['imgUrl']}');">
  112. </div>`
  113. }
  114. }
  115. $('.sec-06 .carousel-inner').html(str);
  116. }
  117. function renderSec07(data) {
  118. let temp = data[4]['data'];
  119. let str = '';
  120. for(let i = 0; i < temp.length; i++){
  121. console.log(temp[i]['imgUrl']);
  122. str+= `
  123. <div class="sec-07__slider-${i+1} sec-07__card col-12 mx-1" onclick="window.open('${temp[i]['link']}');">
  124. <div class="sec-07__imgfr mb-2"><img src="${temp[i]['imgUrl']}" alt=""></div>
  125. <p class="sec-07__cardtxt">${temp[i]['description']}</p>
  126. </div>`
  127. }
  128. $('.sec-07__slider').html(str);
  129. $(".sec-07__slider").slick({
  130. arrows: false,
  131. slidesToShow: 1,
  132. centerMode: true,
  133. infinite: false,
  134. dots: true,
  135. centerPadding: '12px'
  136. });
  137. const cardText = document.querySelectorAll('.sec-07__cardtxt');
  138. cardText.forEach((item, i) => {
  139. let len = item.textContent.length;
  140. if(len > 20) {
  141. let str = item.textContent.substring(0, 25) + '...';
  142. item.textContent = str;
  143. }
  144. })
  145. }
  146. function renderSec08(data) {
  147. let temp = data[5]['data'];
  148. let str = '';
  149. for(let i = 0; i < temp.length; i++){
  150. str+= `<div class="sec-08__slider-${i+1} mx-1" style="width: 70vw; background-image: url('${temp[i]['imgUrl']}');" onclick="window.open('${temp[i]['link']}');"></div>`
  151. }
  152. $('.sec-08__slider').html(str);
  153. $(".sec-08__slider").slick({
  154. arrows: false,
  155. slidesToShow: 1,
  156. centerMode: true,
  157. infinite: false,
  158. dots: false,
  159. centerPadding: '12px'
  160. });
  161. }
  162. function renderSec09(data) {
  163. let temp = data[6]['data'];
  164. let str = '';
  165. for(let i = 0; i < temp.length; i++){
  166. str+= `<div class="sec-09__card" onclick="window.open('${temp[i]['link']}');">
  167. <div class="sec-09__card__imgfr"><img src="${temp[i]['imgUrl']}" alt=""></div>
  168. <p>${temp[i]['description']}</p>
  169. </div>`
  170. }
  171. $('.sec-09__cardgrp').html(str);
  172. }
  173. function renderSec10(data) {
  174. let temp = data[7]['data'];
  175. let str = '';
  176. for(let i = 0; i < temp.length; i++){
  177. str+= `<div class="sec-10__card col-12 mx-1" onclick="window.open('${temp[i]['link']}');">
  178. <div class="sec-10__slider-${i+1} mb-2" style="background-image: url('${temp[i]['imgUrl']}');"></div>
  179. <p class="sec-10__cardtxt">${temp[i]['description']}</p>
  180. </div>`
  181. }
  182. $('.sec-10__slider').html(str);
  183. $(".sec-10__slider").slick({
  184. arrows: false,
  185. slidesToShow: 1,
  186. centerMode: true,
  187. infinite: false,
  188. dots: false,
  189. centerPadding: '12px'
  190. });
  191. }
  192. function renderSec11(data) {
  193. let temp = data[8]['data'];
  194. let str = '';
  195. for(let i = 0; i < temp.length; i++){
  196. str+= `<div class="sec-11__card col-12 mx-1" onclick="window.open('${temp[i]['link']}');">
  197. <div class="sec-11__slider-${i+1} mb-2" style="background-image: url('${temp[i]['imgUrl']}');"></div>
  198. <p class="sec-11__cardtxt">${temp[i]['description']}</p>
  199. </div>`
  200. }
  201. $('.sec-11__slider').html(str);
  202. $(".sec-11__slider").slick({
  203. arrows: false,
  204. slidesToShow: 1,
  205. centerMode: true,
  206. infinite: false,
  207. dots: false,
  208. centerPadding: '12px'
  209. });
  210. }
  211. window.addEventListener('scroll', fixedOnScroll);
  212. const navbar = document.querySelector('.navbar-main');
  213. function fixedOnScroll() {
  214. const sticky = 110;
  215. if(window.pageYOffset >= sticky){
  216. navbar.classList.add('sticky');
  217. } else {
  218. navbar.classList.remove('sticky');
  219. }
  220. }
  221. $('.navbar-toggler').click(function(){
  222. $(".sec-menu").css('display', 'block');
  223. $(".wholeBody").css('overflow-y', 'hidden');
  224. });
  225. $('.navbar-back').click(function(){
  226. $(".sec-menu").css('display', 'none');
  227. $(".wholeBody").css('overflow-y', 'scroll');
  228. });
  229. $('.subexpand').click(function(){
  230. $(this).parent().next().toggleClass('show');
  231. $(this).parent().toggleClass('show');
  232. });
  233. $('.navbar-search').click(function(){
  234. $(".sec-search").css('display', 'block');
  235. $(".wholeBody").css('overflow-y', 'hidden');
  236. })
  237. $('.navbar-backs').click(function(){
  238. $(".sec-search").css('display', 'none');
  239. $(".wholeBody").css('overflow-y', 'scroll');
  240. });
  241. $('.navbar-back-fav').click(function(){
  242. $(".sec-favor").css('display', 'none');
  243. })
  244. $('#videoModal').on('shown.bs.modal', function () {
  245. $('#videoModal iframe').attr('src', 'https://www.youtube.com/embed/G7baBXAhC_I?controls=0&autoplay=1&amp;enablejsapi=1&amp;origin=https%3A%2F%2Fm.hhh.com.tw&amp;widgetid=1');
  246. })
  247. $('#videoModal').on('hidden.bs.modal', function () {
  248. $('#videoModal iframe').removeAttr('src');
  249. });
  250. $('.btn-gotop').click(function () {
  251. $('html, body').animate({
  252. scrollTop: 0
  253. }, 500)
  254. });
  255. $(window).scroll(function() {
  256. if ( $(this).scrollTop() > 500 ){
  257. $('.fixed-btn').fadeIn(222);
  258. } else {
  259. $('.fixed-btn').stop().fadeOut(222);
  260. }
  261. }).scroll();
  262. const searchBtn = document.querySelector('.searchBtn');
  263. const searchBar = document.querySelector('.searchBar');
  264. const searchHotLink = document.querySelectorAll('.sec-search-hots__link');
  265. searchBtn.addEventListener('click', search);
  266. searchBar.addEventListener('keyup', pressSearch);
  267. function search() {
  268. console.log(searchBar.value);
  269. if(searchBar.value == '') {
  270. window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
  271. } else {
  272. window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
  273. console.log(`https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`)
  274. }
  275. }
  276. function pressSearch(e) {
  277. if (e.keyCode === 13) {
  278. e.preventDefault();
  279. search();
  280. }
  281. }
  282. searchHotLink.forEach((item, i) => {
  283. console.log(item.textContent);
  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. });