bhouse.js 6.7 KB

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