bhouse.js 5.4 KB

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