|
|
@ -32,10 +32,18 @@ function relatedCarouselInit() { |
|
|
const root = document.querySelector(".p-related"); |
|
|
const root = document.querySelector(".p-related"); |
|
|
const el = root?.querySelector(".p-related__swiper"); |
|
|
const el = root?.querySelector(".p-related__swiper"); |
|
|
if (!root || !el || !window.Swiper) return; |
|
|
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, { |
|
|
new window.Swiper(el, { |
|
|
slidesPerView: 1.15, |
|
|
slidesPerView: 1.15, |
|
|
spaceBetween: 16, |
|
|
spaceBetween: 16, |
|
|
grabCursor: true, |
|
|
grabCursor: true, |
|
|
|
|
|
watchOverflow: true, |
|
|
pagination: { |
|
|
pagination: { |
|
|
el: root.querySelector(".p-related__pagination"), |
|
|
el: root.querySelector(".p-related__pagination"), |
|
|
clickable: true |
|
|
clickable: true |
|
|
|