index1.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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. 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. 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. renderVideo(result);
  38. });
  39. function renderSec00(data) {
  40. let temp = data[0]['data'];
  41. renderBannerStr('sec-00__slider', temp);
  42. $(".sec-00__slider").slick({
  43. dots: false,
  44. speed: 800,
  45. autoplay: true,
  46. });
  47. }
  48. function renderSec02(data) {
  49. let temp = data[1]['data'];
  50. renderBannerStr('sec-02__slider', temp);
  51. let str = '';
  52. $(".sec-02__slider").slick({
  53. dots: false,
  54. autoplay: true,
  55. arrows: true,
  56. fade: true,
  57. autoplaySpeed: 4000,
  58. });
  59. }
  60. function renderBannerStr(sec, data) {
  61. let str = '';
  62. for(let i = 0; i < data.length; i++){
  63. str+= `<div class="${sec}-${i+1} slide-item" onclick="window.open('${data[i]['link']}');" style="background-image: url('${data[i]['imgUrl']}');"></div>`
  64. }
  65. console.log(str);
  66. $(`.${sec}`).html(str);
  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.webp"></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. if(i === 0) {
  125. str+= `<div class="carousel-item active" onclick="window.open('${temp[i]['link']}');"
  126. style="background-image: url('${temp[i]['imgUrl']}');">
  127. </div>`
  128. } else {
  129. str+= `<div class="carousel-item" onclick="window.open('${temp[i]['link']}');"
  130. style="background-image: url('${temp[i]['imgUrl']}');">
  131. </div>`
  132. }
  133. }
  134. $('.sec-06 .carousel-inner').html(str);
  135. }
  136. function renderSec07(data) {
  137. let temp = data[4]['data'];
  138. let str = '';
  139. for(let i = 0; i < temp.length; i++){
  140. str+= `
  141. <div class="sec-07__slider-${i+1} sec-07__card col-12 mx-1" onclick="window.open('${temp[i]['link']}');">
  142. <div class="sec-07__imgfr mb-2"><img src="${temp[i]['imgUrl']}" alt=""></div>
  143. <p class="sec-07__cardtxt">${temp[i]['description']}</p>
  144. </div>`
  145. }
  146. $('.sec-07__slider').html(str);
  147. $(".sec-07__slider").slick({
  148. arrows: false,
  149. slidesToShow: 1,
  150. centerMode: true,
  151. infinite: false,
  152. dots: true,
  153. centerPadding: '12px'
  154. });
  155. const cardText = document.querySelectorAll('.sec-07__cardtxt');
  156. cardText.forEach((item, i) => {
  157. let len = item.textContent.length;
  158. if(len > 20) {
  159. let str = item.textContent.substring(0, 25) + '...';
  160. item.textContent = str;
  161. }
  162. })
  163. }
  164. function renderSec08(data) {
  165. let temp = data[5]['data'];
  166. let str = '';
  167. for(let i = 0; i < temp.length; i++){
  168. 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>`
  169. }
  170. $('.sec-08__slider').html(str);
  171. $(".sec-08__slider").slick({
  172. autoplay: true,
  173. autoplaySpeed: 8000,
  174. arrows: false,
  175. slidesToShow: 1,
  176. centerMode: true,
  177. infinite: true,
  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. $(".sec-09__cardgrp").slick({
  193. arrows: false,
  194. slidesToShow: 2,
  195. slidesToScroll: 1,
  196. infinite: true,
  197. dots: false,
  198. centerPadding: '10px'
  199. });
  200. }
  201. function renderSec10(data) {
  202. let temp = data[7]['data'];
  203. renderRecStr('sec-10', temp);
  204. }
  205. function renderSec11(data) {
  206. let temp = data[8]['data'];
  207. renderRecStr('sec-11', temp);
  208. }
  209. function renderRecStr(sec, data) {
  210. let str = '';
  211. for(let i = 0; i < data.length; i++){
  212. if(data[i].video == 'true') {
  213. str+= `<div class="${sec}__card col-12 mx-1" onclick="window.open('${data[i]['link']}');">
  214. <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.webp"></div>
  215. <p class="${sec}__cardtxt">${data[i]['description']}</p>
  216. </div>`;
  217. } else {
  218. str+= `<div class="${sec}__card col-12 mx-1" onclick="window.open('${data[i]['link']}');">
  219. <div class="${sec}__slider-${i+1} mb-2 slide-item" style="background-image: url('${data[i]['imgUrl']}');"></div>
  220. <p class="${sec}__cardtxt">${data[i]['description']}</p>
  221. </div>`;
  222. }
  223. }
  224. $(`.${sec}__slider`).html(str);
  225. $(`.${sec}__slider`).slick({
  226. arrows: false,
  227. slidesToShow: 1,
  228. centerMode: true,
  229. infinite: false,
  230. dots: false,
  231. centerPadding: '12px'
  232. });
  233. }
  234. function renderVideo(data) {
  235. let temp = data[9];
  236. $('.sec-05__video__txt').text(temp['title']);
  237. $('.sec-05__video__imgfr').css('background-image', `url(https://img.youtube.com/vi/${temp['yt']}/hqdefault.jpg)`);
  238. $('#videoModal').on('shown.bs.modal', function () {
  239. $('#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`);
  240. });
  241. $('#videoModal').on('hidden.bs.modal', function () {
  242. $('#videoModal iframe').removeAttr('src');
  243. });
  244. }
  245. window.addEventListener('scroll', fixedOnScroll);
  246. const navbar = document.querySelector('.navbar-main');
  247. function fixedOnScroll() {
  248. const sticky = 110;
  249. if(window.pageYOffset >= sticky){
  250. navbar.classList.add('sticky');
  251. } else {
  252. navbar.classList.remove('sticky');
  253. }
  254. }
  255. $('.navbar-toggler').click(function(){
  256. $(".sec-menu").css('display', 'block');
  257. $(".wholeBody").css('overflow-y', 'hidden');
  258. $('.sec-menu-block').addClass('slidein');
  259. $('.sec-menu-block').removeClass('slideout');
  260. });
  261. $('.navbar-back').click(function(){
  262. $(".sec-menu").css('display', 'none');
  263. $(".wholeBody").css('overflow-y', 'scroll');
  264. $('.sec-menu-block').removeClass('slidein');
  265. $('.sec-menu-block').addClass('slideout');
  266. });
  267. $('.subexpand').click(function(){
  268. $(this).parent().next().toggleClass('show');
  269. $(this).parent().toggleClass('show');
  270. });
  271. $('.navbar-search').click(function(){
  272. $(".sec-search").css('display', 'block');
  273. $(".wholeBody").css('overflow-y', 'hidden');
  274. })
  275. $('.navbar-backs').click(function(){
  276. $(".sec-search").css('display', 'none');
  277. $(".wholeBody").css('overflow-y', 'scroll');
  278. });
  279. $('.navbar-back-fav').click(function(){
  280. $(".sec-favor").css('display', 'none');
  281. })
  282. $('.btn-gotop').click(function () {
  283. $('html, body').animate({
  284. scrollTop: 0
  285. }, 500)
  286. });
  287. $(window).scroll(function() {
  288. if ( $(this).scrollTop() > 500 ){
  289. $('.fixed-btn').fadeIn(222);
  290. } else {
  291. $('.fixed-btn').stop().fadeOut(222);
  292. }
  293. }).scroll();
  294. const searchBtn = document.querySelector('.searchBtn');
  295. const searchBar = document.querySelector('.searchBar');
  296. const searchHotLink = document.querySelectorAll('.sec-search-hots__link');
  297. searchBtn.addEventListener('click', search);
  298. searchBar.addEventListener('keyup', pressSearch);
  299. function search() {
  300. if(searchBar.value == '') {
  301. window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
  302. } else {
  303. window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
  304. }
  305. }
  306. function pressSearch(e) {
  307. if (e.keyCode === 13) {
  308. e.preventDefault();
  309. search();
  310. }
  311. }
  312. searchHotLink.forEach((item, i) => {
  313. item.addEventListener('click', function() {
  314. window.location.href = `https://m.hhh.com.tw/search/lists/case/${this.textContent}-keyword/`;
  315. })
  316. })
  317. //jQuery time
  318. var current_fs, next_fs, previous_fs; //fieldsets
  319. var left, opacity, scale; //fieldset properties which we will animate
  320. var animating; //flag to prevent quick multi-click glitches
  321. $(".next").click(function(){
  322. if(animating) return false;
  323. animating = true;
  324. current_fs = $(this).parent().parent();
  325. next_fs = $(this).parent().parent().next();
  326. //activate next step on progressbar using the index of next_fs
  327. $(".form-progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  328. //show the next fieldset
  329. next_fs.animate({opacity: 1}, {
  330. step: function(now, mx) {
  331. //as the opacity of current_fs reduces to 0 - stored in "now"
  332. //1. scale current_fs down to 80%
  333. scale = 0 + (1 + now) * .5 ;
  334. //2. bring next_fs from the right(50%)
  335. left = (now * 50)+"%";
  336. //3. increase opacity of next_fs to 1 as it moves in
  337. opacity = 0 + now;
  338. next_fs.css({
  339. 'transform': 'scale('+scale+')',
  340. });
  341. next_fs.css({'opacity': opacity});
  342. },
  343. duration: 400,
  344. complete: function(){
  345. next_fs.show();
  346. animating = false;
  347. },
  348. //this comes from the custom easing plugin
  349. easing: 'easeInOutBack'
  350. });
  351. //hide the current fieldset with style
  352. current_fs.animate({opacity: 0}, {
  353. step: function(now, mx) {
  354. //as the opacity of current_fs reduces to 0 - stored in "now"
  355. //1. scale current_fs down to 80%
  356. scale = 1 - (1 - now) * 0.2;
  357. //2. bring next_fs from the right(50%)
  358. left = (now * 50)+"%";
  359. //3. increase opacity of next_fs to 1 as it moves in
  360. opacity = 1 - now;
  361. current_fs.css({
  362. 'transform': 'scale('+scale+')',
  363. });
  364. next_fs.css({'opacity': opacity});
  365. },
  366. duration: 400,
  367. complete: function(){
  368. current_fs.hide();
  369. animating = false;
  370. },
  371. //this comes from the custom easing plugin
  372. easing: 'easeInOutBack'
  373. });
  374. });