app/template/default/Block/developmet_comom_slider_right.twig line 1

Open in your IDE?
  1. {% block main %}
  2. <style>
  3. .box_pdcommon_r {
  4.   display: flex;
  5.   flex-wrap: wrap;
  6.   justify-content: space-around;
  7.   width: 100%;
  8.   height: auto;
  9.   z-index: 1;
  10.   background-image: url("https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/wi2025_top_h250.png"); 
  11.   background-size: cover;
  12. }
  13. .box_pdcommon1 {
  14.   display: flex;
  15.   flex-wrap: wrap;
  16.   justify-content: space-around;  
  17.   width: calc(130% / 2 - 5px);
  18.   min-width: 320px;
  19. }
  20. .box_pdcommon2 {
  21.   display: flex;
  22.   flex-wrap: wrap;
  23.   justify-content: space-around;  
  24.   width: calc(100% / 5 - 5px);
  25.   min-width: 150px;
  26.   height: 200px;
  27. }
  28. .box_pdcommon3 {
  29.   display: flex;
  30.   flex-wrap: wrap;
  31.   justify-content: space-around;  
  32.   width: calc(100% / 6 - 5px);
  33.   min-width: 150px;
  34.   height: 200px;
  35.   margin-bottom: 10px;
  36. }
  37. .box_pdcommon4 {
  38.   display: flex;
  39.   flex-wrap: wrap;
  40.   justify-content: space-around;
  41.   width: 320px;
  42.   height: 320px;  
  43.   margin: 10px 0;
  44. }
  45. .box_pdcommon5 {
  46.   width: 100%;
  47.   text-align: center;
  48.   margin-left: auto;
  49.   margin-right: auto;
  50. }
  51. .box_pdcommon6 {
  52.   width: 320px;
  53. }
  54. .fit-picture_pdcommon {
  55.   width: 100%;
  56.   height: 200px;
  57. }
  58. .fit-picture_pdcommon2 {
  59.   width: 320px;
  60.   height: 320px;
  61. }
  62. p.example_pd {
  63.   font-size: 26px;
  64.   color: red;
  65.   margin-top: 20px;
  66.   font-weight: 500;
  67. }
  68. p.example_pd2 {
  69.   font-size: 16px;
  70.   color: blue;
  71.   text-align: center;
  72.   margin-top: 10px;
  73. }
  74. p.example_pd3 {
  75.   font-size: 16px;
  76.   color: #000;
  77.   text-align: center;
  78.   line-height: 16px;
  79.   margin-top: 10px;
  80.   font-weight: 500;
  81. }
  82. .carousel-container {
  83.   display: flex;
  84.   gap: 20px;
  85.   flex-wrap: wrap;
  86.   justify-content: flex-start; /* 左寄せ */
  87.   margin-top: 10px;
  88.   margin-bottom: 10px;
  89. }
  90. .carousel {
  91.   position: relative;
  92.   width: 320px;
  93.   overflow: hidden;
  94.   border: 1px solid #aaa;
  95.   border-radius: 6px;
  96.   background: #fff;
  97. }
  98. .carousel-track {
  99.   display: flex;
  100.   transition: transform 0.5s ease-in-out;
  101. }
  102. .carousel-item {
  103.   flex: 0 0 100%;
  104.   text-align: center;
  105.   background: #ddd;
  106.   padding: 0px 0;
  107.   font-size: 24px;
  108.   width: 320px;
  109.   height: 320px;
  110. }
  111. .prev, .next {
  112.   position: absolute;
  113.   top: 50%;
  114.   transform: translateY(-50%);
  115.   background: rgba(0,0,0,0.5);
  116.   color: #fff;
  117.   border: none;
  118.   font-size: 24px;
  119.   cursor: pointer;
  120.   padding: 5px 10px;
  121. }
  122. .prev { left: 5px; }
  123. .next { right: 5px; }
  124. /* マーカー */
  125. .dots {
  126.   position: absolute;
  127.   bottom: 10px;
  128.   width: 100%;
  129.   display: flex;
  130.   justify-content: center;
  131.   gap: 8px;
  132. }
  133. .dot {
  134.   width: 10px;
  135.   height: 10px;
  136.   border-radius: 50%;
  137.   background: rgba(0,0,0,0.3);
  138.   cursor: pointer;
  139.   transition: background 0.3s;
  140. }
  141. .dot.active {
  142.   background: rgba(0,0,0,0.8);
  143. }
  144. /* レスポンシブ */
  145. @media (max-width: 1000px) {
  146.   .carousel { width: 45%; }
  147. }
  148. @media (max-width: 600px) {
  149.   .carousel { width: 100%; }
  150. }
  151. </style>
  152. <div class="box_pdcommon_r">
  153.   <div class="box_pdcommon1">
  154.     <div class="box_pdcommon5">
  155.       <p class="example_pd">一般工場換気扇</p>  
  156.       <p class="example_pd2">一般工場換気扇</p>  
  157.     </div>
  158.     <div class="box_pdcommon2">
  159.       <a href="https://www.nakatomishop.com/products/detail/1404">
  160.       <img class="fit-picture_pdcommon3" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/N-VF15_150_200.png" width="100%" alt="">
  161.       <p class="example_pd3">N-VF15</p></a>
  162.     </div>
  163.     <div class="box_pdcommon2">
  164.       <a href="https://www.nakatomishop.com/products/detail/1404">
  165.       <img class="fit-picture_pdcommon3" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/N-VF15_150_200.png" width="100%" alt="">
  166.       <p class="example_pd3">111</p></a>
  167.     </div>
  168.     <div class="box_pdcommon2">
  169.       <a href="https://www.nakatomishop.com/products/detail/1404">
  170.       <img class="fit-picture_pdcommon3" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/N-VF15_150_200.png" width="100%" alt="">
  171.       <p class="example_pd3">111</p></a>
  172.     </div>
  173.     <div class="box_pdcommon2">
  174.       <a href="https://www.nakatomishop.com/products/detail/1404">
  175.       <img class="fit-picture_pdcommon3" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/N-VF15_150_200.png" width="100%" alt="">
  176.       <p class="example_pd3">111</p></a>
  177.     </div>
  178.     <div class="box_pdcommon2">
  179.       <a href="https://www.nakatomishop.com/products/detail/1404">
  180.       <img class="fit-picture_pdcommon3" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/image_spacification_150_200.png" width="100%" alt="">
  181.       <p class="example_pd3">111</p></a>
  182.     </div>
  183.   </div>
  184.   <div class="box_pdcommon6">
  185.     <div class="carousel-container">
  186.       <div class="carousel" id="carousel1">
  187.         <div class="carousel-track">
  188.           <div class="carousel-item">
  189.            <a href="https://www.nakatomishop.com/products/detail/1404">
  190.            <img class="fit-picture_pdcommon2" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/image_spacification_320_320.png"></a>
  191.           </div>  
  192.           <div class="carousel-item">
  193.             <a href="https://www.nakatomishop.com/products/detail/1404">
  194.             <img class="fit-picture_pdcommon2" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/image_spacification_320_320.png"></a> 
  195.           </div>
  196.           <div class="carousel-item">
  197.             <a href="https://www.nakatomishop.com/products/detail/1404">
  198.             <img class="fit-picture_pdcommon2" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/image_spacification_320_320.png"></a>
  199.           </div>
  200.           <div class="carousel-item">
  201.             <a href="https://www.nakatomishop.com/products/detail/1404">
  202.             <img class="fit-picture_pdcommon2" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/image_spacification_320_320.png"></a>
  203.           </div>
  204.           <div class="carousel-item">
  205.             <a href="https://www.nakatomishop.com/products/detail/1404">
  206.             <img class="fit-picture_pdcommon2" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/image_spacification_320_320.png"></a>
  207.           </div>
  208.         </div>
  209.           <button class="prev">‹</button>
  210.           <button class="next">›</button>
  211.         <div class="dots"></div> <!-- ← ドットマーカー -->
  212.       </div>
  213.     </div>
  214.   </div>  
  215. </div>
  216. <script>
  217. document.querySelectorAll('.carousel').forEach(carousel => {
  218.   const track = carousel.querySelector('.carousel-track');
  219.   const items = Array.from(track.children);
  220.   const prevButton = carousel.querySelector('.prev');
  221.   const nextButton = carousel.querySelector('.next');
  222.   const dotsContainer = carousel.querySelector('.dots');
  223.   let index = 0;
  224.   let slideWidth = carousel.offsetWidth;
  225.   // 重複防止 — ドットを初期化
  226.   dotsContainer.innerHTML = "";
  227.   // ドット生成
  228.   items.forEach((_, i) => {
  229.     const dot = document.createElement('div');
  230.     dot.classList.add('dot');
  231.     if (i === 0) dot.classList.add('active');
  232.     dot.addEventListener('click', () => {
  233.       index = i;
  234.       moveToSlide();
  235.       updateDots();
  236.       resetAuto();
  237.     });
  238.     dotsContainer.appendChild(dot);
  239.   });
  240.   const dots = dotsContainer.querySelectorAll('.dot');
  241.   const updateSlideWidth = () => {
  242.     slideWidth = carousel.offsetWidth;
  243.     track.style.transition = 'none';
  244.     track.style.transform = `translateX(-${slideWidth * index}px)`;
  245.   };
  246.   window.addEventListener('resize', updateSlideWidth);
  247.   updateSlideWidth();
  248.   const moveToSlide = () => {
  249.     track.style.transition = 'transform 0.5s ease-in-out';
  250.     track.style.transform = `translateX(-${slideWidth * index}px)`;
  251.     updateDots();
  252.   };
  253.   const updateDots = () => {
  254.     dots.forEach(dot => dot.classList.remove('active'));
  255.     dots[index].classList.add('active');
  256.   };
  257.   nextButton.addEventListener('click', () => {
  258.     index = (index + 1) % items.length;
  259.     moveToSlide();
  260.     resetAuto();
  261.   });
  262.   prevButton.addEventListener('click', () => {
  263.     index = (index - 1 + items.length) % items.length;
  264.     moveToSlide();
  265.     resetAuto();
  266.   });
  267.   // 自動スライド
  268.   let interval = setInterval(() => {
  269.     index = (index + 1) % items.length;
  270.     moveToSlide();
  271.   }, 3000);
  272.   const resetAuto = () => {
  273.     clearInterval(interval);
  274.     interval = setInterval(() => {
  275.       index = (index + 1) % items.length;
  276.       moveToSlide();
  277.     }, 3000);
  278.   };
  279.   carousel.addEventListener('mouseenter', () => clearInterval(interval));
  280.   carousel.addEventListener('mouseleave', resetAuto);
  281.   // スワイプ操作
  282.   let startX = 0;
  283.   let isDragging = false;
  284.   carousel.addEventListener('touchstart', e => {
  285.     startX = e.touches[0].clientX;
  286.     isDragging = true;
  287.     track.style.transition = 'none';
  288.   });
  289.   carousel.addEventListener('touchmove', e => {
  290.     if (!isDragging) return;
  291.     const moveX = e.touches[0].clientX - startX;
  292.     track.style.transform = `translateX(${-slideWidth * index + moveX}px)`;
  293.   });
  294.   carousel.addEventListener('touchend', e => {
  295.     isDragging = false;
  296.     const diff = e.changedTouches[0].clientX - startX;
  297.     if (diff > 50) index = (index - 1 + items.length) % items.length;
  298.     else if (diff < -50) index = (index + 1) % items.length;
  299.     moveToSlide();
  300.     resetAuto();
  301.   });
  302. });
  303. </script>
  304. {% endblock %}