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