bhouse.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. return;
  33. }
  34. heightImg.push($(this));
  35. // 預設高度為 0
  36. $(this).css({
  37. 'height': 0 + 'px',
  38. "margin": 'auto',
  39. });
  40. }
  41. if (i === imgCount-1) {
  42. $('#slider-loading').addClass("slider_loading");
  43. $('.style_house_sec02').css("height", "auto");
  44. $('.style_house_sec02 .content').css('opacity', '1');
  45. }
  46. });
  47. let heightImgIndex = [];
  48. function getAllIndex(arr) {
  49. // 篩選符合條件 Index
  50. for (i = 0; i < arr.length; i++) {
  51. if (arr[i].height === 0)
  52. heightImgIndex.push(i);
  53. }
  54. return heightImgIndex;
  55. }
  56. let allSlideImg = document.querySelectorAll('.slide_single_img');
  57. getAllIndex(allSlideImg);
  58. // 取得 slick 當前的 Index
  59. $('.style_house_sec02 .slider').on('beforeChange', function (event, slick, currentSlide, nextSlide) {
  60. for (i = 0; i < heightImgIndex.length; i++) {
  61. console.log(heightImgIndex[i]);
  62. if (nextSlide == heightImgIndex[i]) {
  63. allSlideImg[nextSlide].style.cssText = `
  64. height: 500px;
  65. margin: auto;
  66. `;
  67. } else {
  68. allSlideImg[heightImgIndex[i]].style.height = '0px';
  69. }
  70. }
  71. });
  72. $('.slide_img').each(function () { // jquery.each() 循環讀取所有圖片
  73. var height = $(this).height();
  74. var width = $(this).width();
  75. let x = (height / width);
  76. if (x > 1) {
  77. $(this).css({
  78. 'width': 100 + 'px',
  79. "margin": 'auto',
  80. "padding": "0px",
  81. });
  82. } else {
  83. $(this).css({
  84. "margin-top": '30px',
  85. "padding": "5px",
  86. });
  87. }
  88. });
  89. }
  90. // $('.slide_single_img').each(function (i) { // jquery.each() 循環讀取所有圖片
  91. // let height = $(this).height();
  92. // let width = $(this).width();
  93. // let x = (height / width);
  94. // console.log('index', i);
  95. // console.log('height / width = ', x);
  96. // if (x >= 1) {
  97. // console.log('長圖',i);
  98. // if (i===0) {
  99. // return;
  100. // }
  101. // heightImg.push($(this));
  102. // // 預設高度為 0
  103. // $(this).css({
  104. // 'height': 0 + 'px',
  105. // "margin": 'auto',
  106. // });
  107. // }
  108. // });
  109. // let heightImgIndex = [];
  110. // function getAllIndex(arr) {
  111. // // 篩選符合條件 Index
  112. // for (i = 0; i < arr.length; i++) {
  113. // if (arr[i].height === 0)
  114. // heightImgIndex.push(i);
  115. // }
  116. // return heightImgIndex;
  117. // }
  118. // let allSlideImg = document.querySelectorAll('.slide_single_img');
  119. // getAllIndex(allSlideImg);
  120. // // 取得 slick 當前的 Index
  121. // $('.style_house_sec02 .slider').on('beforeChange', function (event, slick, currentSlide, nextSlide) {
  122. // for (i = 0; i < heightImgIndex.length; i++) {
  123. // console.log(heightImgIndex[i]);
  124. // if (nextSlide == heightImgIndex[i]) {
  125. // allSlideImg[nextSlide].style.cssText = `
  126. // height: 500px;
  127. // margin: auto;
  128. // `;
  129. // } else {
  130. // allSlideImg[heightImgIndex[i]].style.height = '0px';
  131. // }
  132. // }
  133. // });
  134. // $('.slide_img').each(function () { // jquery.each() 循環讀取所有圖片
  135. // var height = $(this).height();
  136. // var width = $(this).width();
  137. // let x = (height / width);
  138. // if (x > 1) {
  139. // $(this).css({
  140. // 'width': 100 + 'px',
  141. // "margin": 'auto',
  142. // "padding": "0px",
  143. // });
  144. // } else {
  145. // $(this).css({
  146. // "margin-top": '30px',
  147. // "padding": "5px",
  148. // });
  149. // }
  150. // });
  151. $('.style_house_sec02 .slider-for').slick({
  152. slidesToShow: 1,
  153. slidesToScroll: 1,
  154. arrows: false,
  155. fade: true,
  156. asNavFor: '.slider-nav'
  157. });
  158. $('.style_house_sec02 .slider-nav').slick({
  159. slidesToShow: 5,
  160. slidesToScroll: 3,
  161. asNavFor: '.slider-for',
  162. dots: false,
  163. arrows: false,
  164. // centerMode: true,
  165. focusOnSelect: true
  166. });
  167. $(document).on("click", ".article__readMore", function (event) {
  168. $('.bhouseweb_loc_sec02').css('height', 'auto');
  169. $('.article__readMore').hide();
  170. });
  171. $(document).on("click", ".bhouseweb_loc_type>label", function (event) {
  172. $(this).siblings().removeClass('select');
  173. $(this).toggleClass("select");
  174. });
  175. $(".bt_slogan_portfolio").click(function () {
  176. $(".bt_slogan_portfolio").fadeOut();
  177. });
  178. $(".bt_slogan").click(function () {
  179. $(".bt_slogan_portfolio").fadeIn();
  180. });
  181. // Navbar Icon
  182. function changeIcon(e) {
  183. const item = document.querySelector('[data-toggle-class]');
  184. item.className === "close-btn" ? item.className = "navbar-toggler-icon" : item.className = "close-btn";
  185. }
  186. $('.furniture_design_content .slider-for').slick({
  187. slidesToShow: 1,
  188. slidesToScroll: 1,
  189. arrows: false,
  190. fade: true,
  191. asNavFor: '.slider-nav'
  192. });
  193. $('.furniture_design_content .slider-nav').slick({
  194. slidesToShow: 3,
  195. slidesToScroll: 1,
  196. asNavFor: '.slider-for',
  197. focusOnSelect: true
  198. });
  199. // 外部連結
  200. let fb_link = `https://www.facebook.com/sharer.php?u=${location.href}`;
  201. let collection_icon_fb = document.getElementById('collection_icon_fb');
  202. $("#collection_icon_fb").attr("href",fb_link);
  203. let line_link = `http://line.naver.jp/R/msg/text/?${location.href}`;
  204. let collection_icon_line = document.getElementById('collection_icon_line');
  205. $("#collection_icon_line").attr("href",line_link);