bhouse.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. if (i === imgCount - 1) {
  48. $('#slider-loading').addClass("slider_loading");
  49. $('.style_house_sec02').css("height", "auto");
  50. $('.style_house_sec02 .content').css('opacity', '1');
  51. }
  52. });
  53. let heightImgIndex = [];
  54. function getAllIndex(arr) {
  55. // 篩選符合條件 Index
  56. for (i = 0; i < arr.length; i++) {
  57. if (arr[i].height === 0)
  58. heightImgIndex.push(i);
  59. }
  60. return heightImgIndex;
  61. }
  62. let allSlideImg = document.querySelectorAll('.slide_single_img');
  63. getAllIndex(allSlideImg);
  64. // 取得 slick 當前的 Index
  65. $('.style_house_sec02 .slider').on('beforeChange', function (event, slick, currentSlide, nextSlide) {
  66. for (i = 0; i < heightImgIndex.length; i++) {
  67. console.log(heightImgIndex[i]);
  68. if (nextSlide == heightImgIndex[i]) {
  69. // allSlideImg[nextSlide].style.cssText = `
  70. // height: 500px;
  71. // margin: auto;
  72. // `;
  73. allSlideImg[nextSlide].classList.add("img-height-vw");
  74. } else {
  75. allSlideImg[heightImgIndex[i]].style.height = '0px';
  76. }
  77. }
  78. });
  79. $('.slide_img').each(function () { // jquery.each() 循環讀取所有圖片
  80. var height = $(this).height();
  81. var width = $(this).width();
  82. let x = (height / width);
  83. if (x > 1) {
  84. $(this).css({
  85. 'width': 100 + 'px',
  86. "margin": 'auto',
  87. "padding": "0px",
  88. });
  89. } else {
  90. $(this).css({
  91. "margin-top": '30px',
  92. "padding": "5px",
  93. });
  94. }
  95. });
  96. }
  97. // $('.slide_single_img').each(function (i) { // jquery.each() 循環讀取所有圖片
  98. // let height = $(this).height();
  99. // let width = $(this).width();
  100. // let x = (height / width);
  101. // console.log('index', i);
  102. // console.log('height / width = ', x);
  103. // if (x >= 1) {
  104. // console.log('長圖',i);
  105. // if (i===0) {
  106. // return;
  107. // }
  108. // heightImg.push($(this));
  109. // // 預設高度為 0
  110. // $(this).css({
  111. // 'height': 0 + 'px',
  112. // "margin": 'auto',
  113. // });
  114. // }
  115. // });
  116. // let heightImgIndex = [];
  117. // function getAllIndex(arr) {
  118. // // 篩選符合條件 Index
  119. // for (i = 0; i < arr.length; i++) {
  120. // if (arr[i].height === 0)
  121. // heightImgIndex.push(i);
  122. // }
  123. // return heightImgIndex;
  124. // }
  125. // let allSlideImg = document.querySelectorAll('.slide_single_img');
  126. // getAllIndex(allSlideImg);
  127. // // 取得 slick 當前的 Index
  128. // $('.style_house_sec02 .slider').on('beforeChange', function (event, slick, currentSlide, nextSlide) {
  129. // for (i = 0; i < heightImgIndex.length; i++) {
  130. // console.log(heightImgIndex[i]);
  131. // if (nextSlide == heightImgIndex[i]) {
  132. // allSlideImg[nextSlide].style.cssText = `
  133. // height: 500px;
  134. // margin: auto;
  135. // `;
  136. // } else {
  137. // allSlideImg[heightImgIndex[i]].style.height = '0px';
  138. // }
  139. // }
  140. // });
  141. // $('.slide_img').each(function () { // jquery.each() 循環讀取所有圖片
  142. // var height = $(this).height();
  143. // var width = $(this).width();
  144. // let x = (height / width);
  145. // if (x > 1) {
  146. // $(this).css({
  147. // 'width': 100 + 'px',
  148. // "margin": 'auto',
  149. // "padding": "0px",
  150. // });
  151. // } else {
  152. // $(this).css({
  153. // "margin-top": '30px',
  154. // "padding": "5px",
  155. // });
  156. // }
  157. // });
  158. $('.style_house_sec02 .slider-for').slick({
  159. slidesToShow: 1,
  160. slidesToScroll: 1,
  161. arrows: true,
  162. fade: true,
  163. asNavFor: '.slider-nav'
  164. });
  165. $('.style_house_sec02 .slider-nav').slick({
  166. slidesToShow: 5,
  167. slidesToScroll: 3,
  168. asNavFor: '.slider-for',
  169. dots: false,
  170. arrows: false,
  171. // centerMode: true,
  172. focusOnSelect: true
  173. });
  174. $(document).on("click", ".article__readMore", function (event) {
  175. $('.bhouseweb_loc_sec02').css('height', 'auto');
  176. $('.article__readMore').hide();
  177. });
  178. $(document).on("click", ".bhouseweb_loc_type>label", function (event) {
  179. $(this).siblings().removeClass('select');
  180. $(this).toggleClass("select");
  181. });
  182. $(".bt_slogan_portfolio").click(function () {
  183. $(".bt_slogan_portfolio").fadeOut();
  184. });
  185. $(".bt_slogan").click(function () {
  186. $(".bt_slogan_portfolio").fadeIn();
  187. });
  188. // Navbar Icon
  189. function changeIcon(e) {
  190. const item = document.querySelector('[data-toggle-class]');
  191. item.className === "close-btn" ? item.className = "navbar-toggler-icon" : item.className = "close-btn";
  192. }
  193. $('.furniture_design_content .slider-for').slick({
  194. slidesToShow: 1,
  195. slidesToScroll: 1,
  196. arrows: false,
  197. fade: true,
  198. asNavFor: '.slider-nav'
  199. });
  200. $('.furniture_design_content .slider-nav').slick({
  201. slidesToShow: 3,
  202. slidesToScroll: 1,
  203. asNavFor: '.slider-for',
  204. focusOnSelect: true
  205. });
  206. // 外部連結
  207. let fb_link = `https://www.facebook.com/sharer.php?u=${location.href}`;
  208. let collection_icon_fb = document.getElementById('collection_icon_fb');
  209. $("#collection_icon_fb").attr("href", fb_link);
  210. let line_link = `http://line.naver.jp/R/msg/text/?${location.href}`;
  211. let collection_icon_line = document.getElementById('collection_icon_line');
  212. $("#collection_icon_line").attr("href", line_link);
  213. // blog 分類篩選
  214. function getCategories(item) {
  215. // 將分類名稱儲存至 localStorage
  216. localStorage.setItem('category', item);
  217. }
  218. // 錨點
  219. $("*").each(function (index, element) {
  220. $(this).click(function (e) {
  221. var target = $(this).attr("data-gt-target");
  222. var duration = $(this).attr("data-gt-duration");
  223. var offset = $(this).attr("data-gt-offset");
  224. if (target) {
  225. //console.log("目標:" + target);
  226. //console.log("時間:" + duration);
  227. //console.log("位移:" + offset);
  228. // 上方位置 = 目標區塊.位移().上方位置
  229. var top = $(target).offset().top;
  230. $("html").stop().animate({
  231. scrollTop: top - offset
  232. }, parseInt(duration));
  233. }
  234. });
  235. });