我在我的团队页面上使用 Glide.js 和 Bootstrap 4 模式来显示被点击的团队成员的简历。这是通过对单击的团队成员使用 getAttribute 并将其startAt: index
用作滑行来完成的。
这段代码第一次完美运行。但是,如果我关闭模态并通过单击任何团队成员再次重新打开它,模态仍然包含所有 html 和滑行控件,但所有幻灯片的内联样式都width:0;
没有显示任何幻灯片,模态显示为空。
此外,即使在初始渲染中,单击时导航点也不起作用。
import Glide from "@glidejs/glide";
class LeadershipSlider {
constructor() {
if (document.querySelector("#leadership-slider")) {
// count how many slides there are
const dotCount = document.querySelectorAll(".leadership-slider__slide").length;
// Generate the HTML for the navigation dots
let dotHTML = "";
for (let i = 0; i < dotCount; i++) {
dotHTML += `<button class="slider__bullet glide__bullet" data-glide-dir="=${i}"></button>`;
}
var glide = new Glide("#leadership-slider", {
type: "carousel",
perView: 1,
gap: 0,
});
// get data attribute for slide to startAt
let slides = document.querySelectorAll(".icon-biography-opt");
for (var i = 0; i < slides.length; i++) {
slides[i].addEventListener("click", function () {
var slideToStart = this.getAttribute("data-leader-index");
glide.update({
startAt: slideToStart,
});
});
}
glide.mount();
// Add the dots HTML to the DOM
document.querySelector(".glide__bullets").insertAdjacentHTML("beforeend", dotHTML);
}
}
}
export default LeadershipSlider;