index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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: "https://m3.hhh.com.tw:18686/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" style="background-image: url('${sub[j]['imgUrl']}');"></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" style="background-image: url('${sub[j]['imgUrl']}');"><img class="tabpar__card__play" src="images/Play-Button.webp"></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" style="background-image: url('${sub[j]['imgUrl']}');"></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. autoplay: true,
  158. autoplaySpeed: 8000,
  159. arrows: false,
  160. slidesToShow: 1,
  161. centerMode: true,
  162. infinite: true,
  163. dots: false,
  164. centerPadding: '12px'
  165. });
  166. }
  167. function renderSec09(data) {
  168. let temp = data[6]['data'];
  169. let str = '';
  170. for(let i = 0; i < temp.length; i++){
  171. str+= `<div class="sec-09__card" onclick="window.open('${temp[i]['link']}');">
  172. <div class="sec-09__card__imgfr"><img src="${temp[i]['imgUrl']}" alt=""></div>
  173. <p>${temp[i]['description']}</p>
  174. </div>`
  175. }
  176. $('.sec-09__cardgrp').html(str);
  177. $(".sec-09__cardgrp").slick({
  178. arrows: false,
  179. slidesToShow: 2,
  180. slidesToScroll: 1,
  181. infinite: true,
  182. dots: false,
  183. centerPadding: '10px'
  184. });
  185. }
  186. function renderSec10(data) {
  187. let temp = data[7]['data'];
  188. renderRecStr('sec-10', temp);
  189. }
  190. function renderSec11(data) {
  191. let temp = data[8]['data'];
  192. renderRecStr('sec-11', temp);
  193. }
  194. function renderRecStr(sec, data) {
  195. let str = '';
  196. for(let i = 0; i < data.length; i++){
  197. if(data[i].video == 'true') {
  198. str+= `<div class="${sec}__card col-12 mx-1" onclick="window.open('${data[i]['link']}');">
  199. <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>
  200. <p class="${sec}__cardtxt">${data[i]['description']}</p>
  201. </div>`;
  202. } else {
  203. str+= `<div class="${sec}__card col-12 mx-1" onclick="window.open('${data[i]['link']}');">
  204. <div class="${sec}__slider-${i+1} mb-2 slide-item" style="background-image: url('${data[i]['imgUrl']}');"></div>
  205. <p class="${sec}__cardtxt">${data[i]['description']}</p>
  206. </div>`;
  207. }
  208. }
  209. $(`.${sec}__slider`).html(str);
  210. $(`.${sec}__slider`).slick({
  211. arrows: false,
  212. slidesToShow: 1,
  213. centerMode: true,
  214. infinite: false,
  215. dots: false,
  216. centerPadding: '12px'
  217. });
  218. }
  219. function renderVideo(data) {
  220. let temp = data[9];
  221. $('.sec-05__video__txt').text(temp['title']);
  222. $('.sec-05__video__imgfr').css('background-image', `url(https://img.youtube.com/vi/${temp['yt']}/hqdefault.jpg)`);
  223. $('#videoModal').on('shown.bs.modal', function () {
  224. $('#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`);
  225. });
  226. $('#videoModal').on('hidden.bs.modal', function () {
  227. $('#videoModal iframe').removeAttr('src');
  228. });
  229. }
  230. window.addEventListener('scroll', fixedOnScroll);
  231. const navbar = document.querySelector('.navbar-main');
  232. function fixedOnScroll() {
  233. const sticky = 110;
  234. if(window.pageYOffset >= sticky){
  235. navbar.classList.add('sticky');
  236. } else {
  237. navbar.classList.remove('sticky');
  238. }
  239. }
  240. $('.navbar-toggler').click(function(){
  241. $(".sec-menu").css('display', 'block');
  242. $(".wholeBody").css('overflow-y', 'hidden');
  243. $('.sec-menu-block').addClass('slidein');
  244. $('.sec-menu-block').removeClass('slideout');
  245. });
  246. $('.navbar-back').click(function(){
  247. $(".sec-menu").css('display', 'none');
  248. $(".wholeBody").css('overflow-y', 'scroll');
  249. $('.sec-menu-block').removeClass('slidein');
  250. $('.sec-menu-block').addClass('slideout');
  251. });
  252. $('.subexpand').click(function(){
  253. $(this).parent().next().toggleClass('show');
  254. $(this).parent().toggleClass('show');
  255. });
  256. $('.navbar-search').click(function(){
  257. $(".sec-search").css('display', 'block');
  258. $(".wholeBody").css('overflow-y', 'hidden');
  259. })
  260. $('.navbar-backs').click(function(){
  261. $(".sec-search").css('display', 'none');
  262. $(".wholeBody").css('overflow-y', 'scroll');
  263. });
  264. $('.navbar-back-fav').click(function(){
  265. $(".sec-favor").css('display', 'none');
  266. })
  267. $('.btn-gotop').click(function () {
  268. $('html, body').animate({
  269. scrollTop: 0
  270. }, 500)
  271. });
  272. $(window).scroll(function() {
  273. if ( $(this).scrollTop() > 500 ){
  274. $('.fixed-btn').fadeIn(222);
  275. } else {
  276. $('.fixed-btn').stop().fadeOut(222);
  277. }
  278. }).scroll();
  279. const searchBtn = document.querySelector('.searchBtn');
  280. const searchBar = document.querySelector('.searchBar');
  281. const searchHotLink = document.querySelectorAll('.sec-search-hots__link');
  282. searchBtn.addEventListener('click', search);
  283. searchBar.addEventListener('keyup', pressSearch);
  284. function search() {
  285. if(searchBar.value == '') {
  286. window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
  287. } else {
  288. window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
  289. }
  290. }
  291. function pressSearch(e) {
  292. if (e.keyCode === 13) {
  293. e.preventDefault();
  294. search();
  295. }
  296. }
  297. searchHotLink.forEach((item, i) => {
  298. item.addEventListener('click', function() {
  299. window.location.href = `https://m.hhh.com.tw/search/lists/case/${this.textContent}-keyword/`;
  300. })
  301. })
  302. //jQuery time
  303. var current_fs, next_fs, previous_fs; //fieldsets
  304. var left, opacity, scale; //fieldset properties which we will animate
  305. var animating; //flag to prevent quick multi-click glitches
  306. $(".next").click(function(){
  307. if(animating) return false;
  308. animating = true;
  309. current_fs = $(this).parent().parent();
  310. next_fs = $(this).parent().parent().next();
  311. //activate next step on progressbar using the index of next_fs
  312. $(".form-progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  313. //show the next fieldset
  314. next_fs.animate({opacity: 1}, {
  315. step: function(now, mx) {
  316. //as the opacity of current_fs reduces to 0 - stored in "now"
  317. //1. scale current_fs down to 80%
  318. scale = 0 + (1 + now) * .5 ;
  319. //2. bring next_fs from the right(50%)
  320. left = (now * 50)+"%";
  321. //3. increase opacity of next_fs to 1 as it moves in
  322. opacity = 0 + now;
  323. next_fs.css({
  324. 'transform': 'scale('+scale+')',
  325. });
  326. next_fs.css({'opacity': opacity});
  327. },
  328. duration: 400,
  329. complete: function(){
  330. next_fs.show();
  331. animating = false;
  332. },
  333. //this comes from the custom easing plugin
  334. easing: 'easeInOutBack'
  335. });
  336. //hide the current fieldset with style
  337. current_fs.animate({opacity: 0}, {
  338. step: function(now, mx) {
  339. //as the opacity of current_fs reduces to 0 - stored in "now"
  340. //1. scale current_fs down to 80%
  341. scale = 1 - (1 - now) * 0.2;
  342. //2. bring next_fs from the right(50%)
  343. left = (now * 50)+"%";
  344. //3. increase opacity of next_fs to 1 as it moves in
  345. opacity = 1 - now;
  346. current_fs.css({
  347. 'transform': 'scale('+scale+')',
  348. });
  349. next_fs.css({'opacity': opacity});
  350. },
  351. duration: 400,
  352. complete: function(){
  353. current_fs.hide();
  354. animating = false;
  355. },
  356. //this comes from the custom easing plugin
  357. easing: 'easeInOutBack'
  358. });
  359. });