index2.js 12 KB

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