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

Open in your IDE?
  1. {% block main %}
  2. <style>
  3. .box_pdcommon_l {
  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_l">
  153.   <div class="box_pdcommon6">
  154.     <div class="carousel-container">
  155.       <div class="carousel" id="carousel2">
  156.         <div class="carousel-track">
  157.           <div class="carousel-item">
  158.            <a href="https://www.nakatomishop.com/products/detail/1404">
  159.            <img class="fit-picture_pdcommon2" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/image_spacification_320_320.png"></a>
  160.           </div>  
  161.           <div class="carousel-item">
  162.             <a href="https://www.nakatomishop.com/products/detail/1404">
  163.             <img class="fit-picture_pdcommon2" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/image_spacification_320_320.png"></a> 
  164.           </div>
  165.           <div class="carousel-item">
  166.             <a href="https://www.nakatomishop.com/products/detail/1404">
  167.             <img class="fit-picture_pdcommon2" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/image_spacification_320_320.png"></a>
  168.           </div>
  169.           <div class="carousel-item">
  170.             <a href="https://www.nakatomishop.com/products/detail/1404">
  171.             <img class="fit-picture_pdcommon2" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/image_spacification_320_320.png"></a>
  172.           </div>
  173.           <div class="carousel-item">
  174.             <a href="https://www.nakatomishop.com/products/detail/1404">
  175.             <img class="fit-picture_pdcommon2" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/image_spacification_320_320.png"></a>
  176.           </div>
  177.         </div>
  178.           <button class="prev">‹</button>
  179.           <button class="next">›</button>
  180.         <div class="dots"></div> <!-- ← ドットマーカー -->
  181.       </div>
  182.     </div>
  183.   </div>
  184.   <div class="box_pdcommon1">
  185.     <div class="box_pdcommon5">
  186.       <p class="example_pd">一般工場換気扇</p>  
  187.       <p class="example_pd2">一般工場換気扇</p>  
  188.     </div>
  189.     <div class="box_pdcommon2">
  190.       <a href="https://www.nakatomishop.com/products/detail/1404">
  191.       <img class="fit-picture_pdcommon3" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/N-VF15_150_200.png" width="100%" alt="">
  192.       <p class="example_pd3">N-VF15</p></a>
  193.     </div>
  194.     <div class="box_pdcommon2">
  195.       <a href="https://www.nakatomishop.com/products/detail/1404">
  196.       <img class="fit-picture_pdcommon3" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/N-VF15_150_200.png" width="100%" alt="">
  197.       <p class="example_pd3">111</p></a>
  198.     </div>
  199.     <div class="box_pdcommon2">
  200.       <a href="https://www.nakatomishop.com/products/detail/1404">
  201.       <img class="fit-picture_pdcommon3" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/N-VF15_150_200.png" width="100%" alt="">
  202.       <p class="example_pd3">111</p></a>
  203.     </div>
  204.     <div class="box_pdcommon2">
  205.       <a href="https://www.nakatomishop.com/products/detail/1404">
  206.       <img class="fit-picture_pdcommon3" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/N-VF15_150_200.png" width="100%" alt="">
  207.       <p class="example_pd3">111</p></a>
  208.     </div>
  209.     <div class="box_pdcommon2">
  210.       <a href="https://www.nakatomishop.com/products/detail/1404">
  211.       <img class="fit-picture_pdcommon3" src="https://nakatomishop.sakura.ne.jp/prod/merchandiseimage/25winter/image_spacification_150_200.png" width="100%" alt="">
  212.       <p class="example_pd3">111</p></a>
  213.     </div>
  214.   </div>
  215.   
  216. </div>
  217. <script>
  218. document.querySelectorAll('.carousel').forEach(carousel => {
  219.   const track = carousel.querySelector('.carousel-track');
  220.   const items = Array.from(track.children);
  221.   const prevButton = carousel.querySelector('.prev');
  222.   const nextButton = carousel.querySelector('.next');
  223.   const dotsContainer = carousel.querySelector('.dots');
  224.   let index = 0;
  225.   let slideWidth = carousel.offsetWidth;
  226.   // 重複防止 — ドットを初期化
  227.   dotsContainer.innerHTML = "";
  228.   // ドット生成
  229.   items.forEach((_, i) => {
  230.     const dot = document.createElement('div');
  231.     dot.classList.add('dot');
  232.     if (i === 0) dot.classList.add('active');
  233.     dot.addEventListener('click', () => {
  234.       index = i;
  235.       moveToSlide();
  236.       updateDots();
  237.       resetAuto();
  238.     });
  239.     dotsContainer.appendChild(dot);
  240.   });
  241.   const dots = dotsContainer.querySelectorAll('.dot');
  242.   const updateSlideWidth = () => {
  243.     slideWidth = carousel.offsetWidth;
  244.     track.style.transition = 'none';
  245.     track.style.transform = `translateX(-${slideWidth * index}px)`;
  246.   };
  247.   window.addEventListener('resize', updateSlideWidth);
  248.   updateSlideWidth();
  249.   const moveToSlide = () => {
  250.     track.style.transition = 'transform 0.5s ease-in-out';
  251.     track.style.transform = `translateX(-${slideWidth * index}px)`;
  252.     updateDots();
  253.   };
  254.   const updateDots = () => {
  255.     dots.forEach(dot => dot.classList.remove('active'));
  256.     dots[index].classList.add('active');
  257.   };
  258.   nextButton.addEventListener('click', () => {
  259.     index = (index + 1) % items.length;
  260.     moveToSlide();
  261.     resetAuto();
  262.   });
  263.   prevButton.addEventListener('click', () => {
  264.     index = (index - 1 + items.length) % items.length;
  265.     moveToSlide();
  266.     resetAuto();
  267.   });
  268.   // 自動スライド
  269.   let interval = setInterval(() => {
  270.     index = (index + 1) % items.length;
  271.     moveToSlide();
  272.   }, 3000);
  273.   const resetAuto = () => {
  274.     clearInterval(interval);
  275.     interval = setInterval(() => {
  276.       index = (index + 1) % items.length;
  277.       moveToSlide();
  278.     }, 3000);
  279.   };
  280.   carousel.addEventListener('mouseenter', () => clearInterval(interval));
  281.   carousel.addEventListener('mouseleave', resetAuto);
  282.   // スワイプ操作
  283.   let startX = 0;
  284.   let isDragging = false;
  285.   carousel.addEventListener('touchstart', e => {
  286.     startX = e.touches[0].clientX;
  287.     isDragging = true;
  288.     track.style.transition = 'none';
  289.   });
  290.   carousel.addEventListener('touchmove', e => {
  291.     if (!isDragging) return;
  292.     const moveX = e.touches[0].clientX - startX;
  293.     track.style.transform = `translateX(${-slideWidth * index + moveX}px)`;
  294.   });
  295.   carousel.addEventListener('touchend', e => {
  296.     isDragging = false;
  297.     const diff = e.changedTouches[0].clientX - startX;
  298.     if (diff > 50) index = (index - 1 + items.length) % items.length;
  299.     else if (diff < -50) index = (index + 1) % items.length;
  300.     moveToSlide();
  301.     resetAuto();
  302.   });
  303. });
  304. </script>
  305. {% endblock %}