bhouse.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. $(".responsive").slick({
  2. dots: true,
  3. slidesToShow: 1,
  4. slidesToScroll: 1,
  5. autoplay: true,
  6. autoplaySpeed: 3000,
  7. arrows: false,
  8. });
  9. // 直式輪播圖動態更改高度
  10. function changeHeight() {
  11. let firstImg = $('.style_house_sec02_slide div:first-child img');
  12. let firstImgHeight = firstImg.css('height');
  13. $('.style_house_sec02_slide .vertical-img').css("height", `${firstImgHeight}`)
  14. }
  15. changeHeight();
  16. $(window).resize(function () {
  17. setTimeout(() => {
  18. changeHeight();
  19. }, 100)
  20. });
  21. let imgCount = $(".slide_single_img").length;
  22. let heightImg = [];
  23. window.onload = function () {
  24. console.log('onload');
  25. $('.slide_single_img').each(function (i, array) { // jquery.each() 循環讀取所有圖片
  26. let height = $(this).height();
  27. let width = $(this).width();
  28. let x = (height / width);
  29. console.log('height / width = ', x);
  30. if (x >= 1) {
  31. if (i === 0) {
  32. $(this).addClass("img-height-vw");
  33. // $(this).css({
  34. // 'height': 500 + 'px',
  35. // "margin": 'auto',
  36. // });
  37. } else {
  38. // 預設高度為 0
  39. $(this).css({
  40. 'height': 0 + 'px',
  41. 'object-fit': 'contain',
  42. // 'margin': 'auto',
  43. });
  44. }
  45. heightImg.push($(this));
  46. }
  47. // else {
  48. // $(this).css({
  49. // 'height': 580 + 'px',
  50. // 'object-fit': 'cover'
  51. // });
  52. // console.log('this',this);
  53. // }
  54. if (i === imgCount - 1) {
  55. $('#slider-loading').addClass("slider_loading");
  56. $('.style_house_sec02').css("height", "auto");
  57. $('.style_house_sec02 .content').css('opacity', '1');
  58. }
  59. });
  60. let heightImgIndex = [];
  61. function getAllIndex(arr) {
  62. // 篩選符合條件 Index
  63. for (i = 0; i < arr.length; i++) {
  64. if (arr[i].height === 0)
  65. heightImgIndex.push(i);
  66. }
  67. return heightImgIndex;
  68. }
  69. let allSlideImg = document.querySelectorAll('.slide_single_img');
  70. getAllIndex(allSlideImg);
  71. // 取得 slick 當前的 Index
  72. $('.style_house_sec02 .slider').on('beforeChange', function (event, slick, currentSlide, nextSlide) {
  73. for (i = 0; i < heightImgIndex.length; i++) {
  74. console.log(heightImgIndex[i]);
  75. if (nextSlide == heightImgIndex[i]) {
  76. // allSlideImg[nextSlide].style.cssText = `
  77. // height: 500px;
  78. // margin: auto;
  79. // `;
  80. allSlideImg[nextSlide].classList.add("img-height-vw");
  81. } else {
  82. allSlideImg[heightImgIndex[i]].style.height = '0px';
  83. }
  84. }
  85. });
  86. $('.slide_img').each(function () { // jquery.each() 循環讀取所有圖片
  87. var height = $(this).height();
  88. var width = $(this).width();
  89. let x = (height / width);
  90. if (x > 1) {
  91. $(this).css({
  92. 'width': 130 + 'px',
  93. "margin": 'auto',
  94. "padding": "5px",
  95. });
  96. } else {
  97. $(this).css({
  98. "margin-top": '30px',
  99. "padding": "5px",
  100. });
  101. }
  102. });
  103. }
  104. // $('.slide_single_img').each(function (i) { // jquery.each() 循環讀取所有圖片
  105. // let height = $(this).height();
  106. // let width = $(this).width();
  107. // let x = (height / width);
  108. // console.log('index', i);
  109. // console.log('height / width = ', x);
  110. // if (x >= 1) {
  111. // console.log('長圖',i);
  112. // if (i===0) {
  113. // return;
  114. // }
  115. // heightImg.push($(this));
  116. // // 預設高度為 0
  117. // $(this).css({
  118. // 'height': 0 + 'px',
  119. // "margin": 'auto',
  120. // });
  121. // }
  122. // });
  123. // let heightImgIndex = [];
  124. // function getAllIndex(arr) {
  125. // // 篩選符合條件 Index
  126. // for (i = 0; i < arr.length; i++) {
  127. // if (arr[i].height === 0)
  128. // heightImgIndex.push(i);
  129. // }
  130. // return heightImgIndex;
  131. // }
  132. // let allSlideImg = document.querySelectorAll('.slide_single_img');
  133. // getAllIndex(allSlideImg);
  134. // // 取得 slick 當前的 Index
  135. // $('.style_house_sec02 .slider').on('beforeChange', function (event, slick, currentSlide, nextSlide) {
  136. // for (i = 0; i < heightImgIndex.length; i++) {
  137. // console.log(heightImgIndex[i]);
  138. // if (nextSlide == heightImgIndex[i]) {
  139. // allSlideImg[nextSlide].style.cssText = `
  140. // height: 500px;
  141. // margin: auto;
  142. // `;
  143. // } else {
  144. // allSlideImg[heightImgIndex[i]].style.height = '0px';
  145. // }
  146. // }
  147. // });
  148. // $('.slide_img').each(function () { // jquery.each() 循環讀取所有圖片
  149. // var height = $(this).height();
  150. // var width = $(this).width();
  151. // let x = (height / width);
  152. // if (x > 1) {
  153. // $(this).css({
  154. // 'width': 100 + 'px',
  155. // "margin": 'auto',
  156. // "padding": "0px",
  157. // });
  158. // } else {
  159. // $(this).css({
  160. // "margin-top": '30px',
  161. // "padding": "5px",
  162. // });
  163. // }
  164. // });
  165. $('.style_house_sec02 .slider-for').slick({
  166. slidesToShow: 1,
  167. slidesToScroll: 1,
  168. arrows: true,
  169. fade: true,
  170. asNavFor: '.slider-nav',
  171. prevArrow: '<button type="button" class="slick-prev"><img src="/img/arrow_left.png" alt="" width="50"></button>',
  172. nextArrow: '<button type="button" class="slick-next"><img src="/img/arrow_right.png" alt="" width="50"></button>'
  173. });
  174. $('.style_house_sec02 .slider-nav').slick({
  175. slidesToShow: 5,
  176. slidesToScroll: 3,
  177. asNavFor: '.slider-for',
  178. dots: false,
  179. arrows: false,
  180. // centerMode: true,
  181. focusOnSelect: true
  182. });
  183. $(document).on("click", ".article__readMore", function (event) {
  184. $('.bhouseweb_loc_sec02').css('height', 'auto');
  185. $('.article__readMore').hide();
  186. });
  187. $(document).on("click", ".bhouseweb_loc_type>label", function (event) {
  188. $(this).siblings().removeClass('select');
  189. $(this).toggleClass("select");
  190. });
  191. $(".bt_slogan_portfolio").click(function () {
  192. $(".bt_slogan_portfolio").fadeOut();
  193. });
  194. $(".bt_slogan").click(function () {
  195. $(".bt_slogan_portfolio").fadeIn();
  196. });
  197. // Navbar Icon
  198. function changeIcon(e) {
  199. const item = document.querySelector('[data-toggle-class]');
  200. item.className === "close-btn" ? item.className = "navbar-toggler-icon" : item.className = "close-btn";
  201. }
  202. $('.furniture_design_content .slider-for').slick({
  203. slidesToShow: 1,
  204. slidesToScroll: 1,
  205. arrows: false,
  206. fade: true,
  207. asNavFor: '.slider-nav'
  208. });
  209. $('.furniture_design_content .slider-nav').slick({
  210. slidesToShow: 3,
  211. slidesToScroll: 1,
  212. asNavFor: '.slider-for',
  213. focusOnSelect: true
  214. });
  215. // 外部連結
  216. let fb_link = `https://www.facebook.com/sharer.php?u=${location.href}`;
  217. let fb_list = document.querySelectorAll('#collection_icon_fb');
  218. for (let i = 0; i < fb_list.length; i++) {
  219. const item = fb_list[i];
  220. item.setAttribute("href", fb_link);
  221. }
  222. let line_link = `http://line.naver.jp/R/msg/text/?${location.href}`;
  223. let line_list = document.querySelectorAll('#collection_icon_line');
  224. for (let i = 0; i < line_list.length; i++) {
  225. const item = line_list[i];
  226. item.setAttribute("href", line_link);
  227. }
  228. // blog 分類篩選
  229. function getCategories(item) {
  230. // 將分類名稱儲存至 localStorage
  231. localStorage.setItem('category', item);
  232. }
  233. // 錨點
  234. $("*").each(function (index, element) {
  235. $(this).click(function (e) {
  236. var target = $(this).attr("data-gt-target");
  237. var duration = $(this).attr("data-gt-duration");
  238. var offset = $(this).attr("data-gt-offset");
  239. if (target) {
  240. //console.log("目標:" + target);
  241. //console.log("時間:" + duration);
  242. //console.log("位移:" + offset);
  243. // 上方位置 = 目標區塊.位移().上方位置
  244. var top = $(target).offset().top;
  245. $("html").stop().animate({
  246. scrollTop: top - offset
  247. }, parseInt(duration));
  248. }
  249. });
  250. });
  251. let tagList = [];
  252. (function getContentsData() {
  253. // 線上版網址 https://bhouse3.ptt.cx:9002/api/contents?url=/blog
  254. // 本地端網址 http://localhost:9001/api/
  255. fetch('https://bhouse3.ptt.cx:9002/api/contents?url=/blog').then(res => res.json()).then(list => {
  256. list.map(({ blog_tag }) => {
  257. if (blog_tag) {
  258. let tagText = blog_tag.replace("[", "").replace("]", "");
  259. let tagArr = tagText.split(',');
  260. tagArr.map(e => {
  261. tagList.push(e);
  262. })
  263. // 移除重複字串
  264. tagList = tagList.filter((item, index) => tagList.indexOf(item) === index);
  265. // 隨機排序
  266. tagList = tagList.sort(() => 0.5 - Math.random());
  267. const dom = document.querySelectorAll('.blog-tags');
  268. let tagTemplate = [];
  269. // 標籤顯示兩排
  270. let count = 0;
  271. if (document.body.offsetWidth<767) {
  272. count = 8;
  273. } else {
  274. count = 10;
  275. }
  276. for (let i = 0; i < count; i++) {
  277. const element = tagList[i];
  278. let content = `<a href="/blog?tags=${element}">${element}</a>`;
  279. tagTemplate.push(content);
  280. }
  281. // 移除陣列逗號
  282. if (dom) {
  283. for (let i = 0; i < dom.length; i++) {
  284. const element = dom[i];
  285. element.innerHTML = tagTemplate.join("");
  286. }
  287. }
  288. }
  289. })
  290. })
  291. })();
  292. function changeIcon(e) {
  293. const item = document.querySelector('[data-toggle-class]');
  294. item.className === "close-btn" ? item.className = "navbar-toggler-icon" : item.className = "close-btn";
  295. }
  296. $(document).on("click", "#menutoggle", function (event) {
  297. $('.nav-mobile ').toggleClass("bg-3C7062")
  298. });