diff --git a/public/themes/dist_static/static/js/product.js b/public/themes/dist_static/static/js/product.js index bb083c1..b47e3c6 100644 --- a/public/themes/dist_static/static/js/product.js +++ b/public/themes/dist_static/static/js/product.js @@ -32,10 +32,18 @@ function relatedCarouselInit() { const root = document.querySelector(".p-related"); const el = root?.querySelector(".p-related__swiper"); if (!root || !el || !window.Swiper) return; + const slideCount = el.querySelectorAll(".swiper-wrapper > .swiper-slide").length; + // 一屏展示 4 条,不超过 4 条时隐藏切换按钮 + if (slideCount <= 4) { + root.querySelectorAll(".p-related__header .s-arrows").forEach((node) => { + node.style.display = "none"; + }); + } new window.Swiper(el, { slidesPerView: 1.15, spaceBetween: 16, grabCursor: true, + watchOverflow: true, pagination: { el: root.querySelector(".p-related__pagination"), clickable: true