bhouse.js 6.8 KB

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