bhouse.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. $('.slide_single_img').each(function (i) { // jquery.each() 循環讀取所有圖片
  24. let height = $(this).height();
  25. let width = $(this).width();
  26. let x = (height / width);
  27. console.log('index', i);
  28. console.log('height / width = ', x);
  29. if (x >= 1 && i !== 0) {
  30. heightImg.push($(this));
  31. // 預設高度為 0
  32. $(this).css({
  33. 'height': 0 + 'px',
  34. "margin": 'auto',
  35. });
  36. }
  37. });
  38. let heightImgIndex = [];
  39. function getAllIndex(arr) {
  40. // 篩選符合條件 Index
  41. for (i = 0; i < arr.length; i++) {
  42. if (arr[i].height === 0)
  43. heightImgIndex.push(i);
  44. }
  45. return heightImgIndex;
  46. }
  47. let allSlideImg = document.querySelectorAll('.slide_single_img');
  48. getAllIndex(allSlideImg);
  49. // 取得 slick 當前的 Index
  50. $('.style_house_sec02 .slider').on('beforeChange', function (event, slick, currentSlide, nextSlide) {
  51. for (i = 0; i < heightImgIndex.length; i++) {
  52. console.log(heightImgIndex[i]);
  53. if (nextSlide == heightImgIndex[i]) {
  54. allSlideImg[nextSlide].style.cssText = `
  55. height: 500px;
  56. margin: auto;
  57. `;
  58. } else {
  59. allSlideImg[heightImgIndex[i]].style.height = '0px';
  60. }
  61. }
  62. });
  63. $('.slide_img').each(function () { // jquery.each() 循環讀取所有圖片
  64. var height = $(this).height();
  65. var width = $(this).width();
  66. let x = (height / width);
  67. if (x > 1) {
  68. $(this).css({
  69. 'width': 100 + 'px',
  70. "margin": 'auto',
  71. "padding": "0px",
  72. });
  73. } else {
  74. $(this).css({
  75. "margin-top": '30px',
  76. "padding": "5px",
  77. });
  78. }
  79. });
  80. $('.style_house_sec02 .slider-for').slick({
  81. slidesToShow: 1,
  82. slidesToScroll: 1,
  83. arrows: false,
  84. fade: true,
  85. asNavFor: '.slider-nav'
  86. });
  87. $('.style_house_sec02 .slider-nav').slick({
  88. slidesToShow: 5,
  89. slidesToScroll: 3,
  90. asNavFor: '.slider-for',
  91. dots: false,
  92. arrows: false,
  93. // centerMode: true,
  94. focusOnSelect: true
  95. });
  96. $(document).on("click", ".article__readMore", function (event) {
  97. $('.bhouseweb_loc_sec02').css('height', 'auto');
  98. $('.article__readMore').hide();
  99. });
  100. $(document).on("click", ".bhouseweb_loc_type>a", function (event) {
  101. $(this).siblings().removeClass('select');
  102. $(this).toggleClass("select");
  103. });
  104. $(".bt_slogan_portfolio").click(function () {
  105. $(".bt_slogan_portfolio").fadeOut();
  106. });
  107. $(".bt_slogan").click(function () {
  108. $(".bt_slogan_portfolio").fadeIn();
  109. });
  110. // Navbar Icon
  111. function changeIcon(e) {
  112. const item = document.querySelector('[data-toggle-class]');
  113. item.className === "close-btn" ? item.className = "navbar-toggler-icon" : item.className = "close-btn";
  114. }
  115. $('.furniture_design_content .slider-for').slick({
  116. slidesToShow: 1,
  117. slidesToScroll: 1,
  118. arrows: false,
  119. fade: true,
  120. asNavFor: '.slider-nav'
  121. });
  122. $('.furniture_design_content .slider-nav').slick({
  123. slidesToShow: 3,
  124. slidesToScroll: 1,
  125. asNavFor: '.slider-for',
  126. focusOnSelect: true
  127. });