bhouse.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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': 100 + 'px',
  93. "margin": 'auto',
  94. "padding": "0px",
  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 collection_icon_fb = document.getElementById('collection_icon_fb');
  218. $("#collection_icon_fb").attr("href", fb_link);
  219. let line_link = `http://line.naver.jp/R/msg/text/?${location.href}`;
  220. let collection_icon_line = document.getElementById('collection_icon_line');
  221. $("#collection_icon_line").attr("href", line_link);
  222. // blog 分類篩選
  223. function getCategories(item) {
  224. // 將分類名稱儲存至 localStorage
  225. localStorage.setItem('category', item);
  226. }
  227. // 錨點
  228. $("*").each(function (index, element) {
  229. $(this).click(function (e) {
  230. var target = $(this).attr("data-gt-target");
  231. var duration = $(this).attr("data-gt-duration");
  232. var offset = $(this).attr("data-gt-offset");
  233. if (target) {
  234. //console.log("目標:" + target);
  235. //console.log("時間:" + duration);
  236. //console.log("位移:" + offset);
  237. // 上方位置 = 目標區塊.位移().上方位置
  238. var top = $(target).offset().top;
  239. $("html").stop().animate({
  240. scrollTop: top - offset
  241. }, parseInt(duration));
  242. }
  243. });
  244. });